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
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <climits>

using namespace std;

long a[1000002];

int main()
{
	long n, l;
	scanf("%ld", &n);
	for (long i = 1; i <= n; ++i)
	{
		scanf("%ld", &l);
		a[l] = i;
	}
	long long res = 1;
	long f = n + 1 + n;
	long _min = a[n], _max = a[n];
	for (long i = 2; i <= n; ++i)
	{
		long m = (f - i) / 2;
		if (a[m] < _min)
			_min = a[m];
		if (a[m] > _max)
			_max = a[m];
		if (_max - _min < i)
			res += i - (std::max(i, _max) - std::min(n - i + 1, _min));
	}

	printf("%ld %lld", f, res);
	return 0;
}