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
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> rank(n);
    vector<int> where(n+1);
    for(int i=0; i<n; i++)
    {
        cin >> rank[i];
        where[rank[i]]=i;
    }
    int b = where[n];
    int e = where[n];
    long long wynik=0;
    for(int i=1; i<=n; i++)
    {
        int k=i/2+1;
        int neww=n-k+1;
        if(where[neww]<b)
            b=where[neww];
        if(where[neww]>e)
            e=where[neww];
        if(e-b+1>i)
            continue;
        int maxR=min(b, n-i);
        int maxL=max(0, e+1-i);
        wynik+=(maxR-maxL+1);
    }
    cout << 2*n+1 << ' ' << wynik << "\n";
    return 0;
}