#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = b; a <= i; i--)
#define cat(x) cerr << #x << " = " << x << '\n';
using ll = long long;
using namespace std;
const int N = 1 << 20;
int n, a[N];
ll res;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
rep(i, 1, n) {
int x;
cin >> x;
a[x] = i;
}
int l = n;
int r = 1;
rep(len, 1, n) {
int id = (2 * n - len + 1) / 2;
l = min(l, a[id]);
r = max(r, a[id]);
int x = max(1, r - len + 1);
int y = min(l, n - len + 1);
res += max(0, y - x + 1);
}
cout << 2 * n + 1 << ' ' << res << '\n';
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 | #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = b; a <= i; i--) #define cat(x) cerr << #x << " = " << x << '\n'; using ll = long long; using namespace std; const int N = 1 << 20; int n, a[N]; ll res; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n; rep(i, 1, n) { int x; cin >> x; a[x] = i; } int l = n; int r = 1; rep(len, 1, n) { int id = (2 * n - len + 1) / 2; l = min(l, a[id]); r = max(r, a[id]); int x = max(1, r - len + 1); int y = min(l, n - len + 1); res += max(0, y - x + 1); } cout << 2 * n + 1 << ' ' << res << '\n'; return 0; } |
English