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;

using ll = long long;

const int N = 1e6 + 7;
int per[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int a;
        scanf("%d", &a);
        per[a] = i;
    }

    int l = n + 1, r = 0;
    ll ans = 0;
    for (int k = 1; k <= n; ++k) {
        int p = per[n - k / 2];
        l = min(l, p);
        r = max(r, p);
        int d = r - l + 1;
        if (d > k)
            continue;
        int need = k - d;
        int ma = min(l - 1, need);
        int mi = max(0, need - (n - r));
        ans += ma - mi + 1;
    }
    printf("%d %lld\n", 2 * n + 1, ans);

    return 0;
}