1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

struct para
{
    int x, y;
};

int main()
{
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    long long cel = n+1+n;
    long long il_spos = 1;      //dla samego n;
    cout<<cel<<" ";
    vector<int> pos(n+1);
    for (int i = 0; i < n; i++)
    {
        pos[a[i]]=i;
    }
    int npom = (n-1)/2;
    int rozpmin = pos[n];
    int rozpmax = pos[n];
    int x, k;
    for (int i = n-1; i >npom; i--)
    {
        rozpmax = max(rozpmax, pos[i]);
        rozpmin = min(rozpmin, pos[i]);
        x = rozpmax-rozpmin+1;
        k = n-i;
        for (int j = rozpmin-k; j <=rozpmin;j++)
        {
            if (j>0)
            {
            if ((j+2*k >= rozpmax) &&  (j+2*k<=n))
                il_spos++;
            if ((j+2*k >= rozpmax) &&  (j+2*k<=n))
                il_spos++;
            }

        }
        /*int lim1 = 2*k-x, lim11 = 2*k-x+1, lim2 = n-rozpmax, lim3 = rozpmin-1;
        if (((2*k) >= x) && ((2*k)<=n))
        {
                il_spos+=(min(min(lim2, lim3), lim1)+1);
                cout << (min(min(lim2, lim3), lim1)+1)<<" ";
        }
        if (((2*k+1)>=x) && ((2*k+1)<=n))
        {
            il_spos+=(min(min(lim2, lim3), lim11)+1);
            cout << (min(min(lim2, lim3), lim11)+1)<<" "<<lim2<<lim3<<lim11;
        }
        cout<<i<<" "<<il_spos<<endl;*/
    }
    cout << il_spos;
    return 0;
}