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
67
// Krzysztof Baranski (2021.12.09)
#include <cstdio>
using namespace std;

int n;
int rates[1000009];
int position[1000009];

inline int min(int x, int y) {
    return (x < y ? x : y);
}

int main() {
    scanf("%d\n", &n);

    int range_begin, range_end;
    for(int i=0; i<n; ++i) {
        scanf("%d", rates + i);
        position[rates[i]] = i;
        if(rates[i] == n) {
            range_begin = i;
            range_end = i;
        }
    }

    int result_value = 2*n + 1;
    long long result_count = 1;
    int max_counted_range_size = 1;

    if(n == 1) {
        printf("%d %lld\n", result_value, result_count);
        return 0;
    }

    int range = 1;
    for(int k = 1; k < n; ++k) {
        int num = n-k;
        range_begin = ((position[num] < range_begin) ? position[num] : range_begin);
        range_end = ((position[num] > range_end) ? position[num] : range_end);
        int range_size = (range_end - range_begin + 1);
        int max_range_size = min(2*k+1, n);

        if(range_size > max_range_size) {
            continue;
        }
        if(range_size > max_counted_range_size) {
            result_count++;
            max_counted_range_size = range_size;
        }

        while(max_counted_range_size < max_range_size) {
            max_counted_range_size++;
            int count_more = (range_size 
                + min(max_counted_range_size - range_size, range_begin) 
                + min(max_counted_range_size - range_size, n - range_end - 1) 
                - max_counted_range_size 
                + 1);
            if(count_more > 0) result_count += count_more;
        }

        if(max_counted_range_size > n) break;
    }

    printf("%d %lld\n", result_value, result_count);

    return 0;
}