#include <iostream> using namespace std; int main() { int n; long long w = 0; cin >> n; int T[n]; for (int i = 0; i < n; i++) cin >> T[i]; int l = 1, p = 1; for (int i = 0; T[i] <= (n + 1)/2; i++) l++; for (int i = n - 1; T[i] <= (n + 1)/2; i--) p++; w += (long long)p * l; l--; p = n - p; int a = (n + 1)/2; while (l < p) { if (T[l] == a) { w++; l++; a++; } else if (T[p] == a) { w++; p--; a++; } else break; } if (a == n) w--; cout << 2*n+1 << " " << w + 1 << endl; return 0; }
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 | #include <iostream> using namespace std; int main() { int n; long long w = 0; cin >> n; int T[n]; for (int i = 0; i < n; i++) cin >> T[i]; int l = 1, p = 1; for (int i = 0; T[i] <= (n + 1)/2; i++) l++; for (int i = n - 1; T[i] <= (n + 1)/2; i--) p++; w += (long long)p * l; l--; p = n - p; int a = (n + 1)/2; while (l < p) { if (T[l] == a) { w++; l++; a++; } else if (T[p] == a) { w++; p--; a++; } else break; } if (a == n) w--; cout << 2*n+1 << " " << w + 1 << endl; return 0; } |