#define _USE_MATH_DEFINES #include <bits/stdc++.h> #ifdef LOC #include "debuglib.h" #else #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using Vi = vector<int>; using Pii = pair<int, int>; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(12); int n; cin >> n; Vi perm(n); each(p, perm) cin >> p, p--; Vi pos(n); rep(i, 0, n) pos[perm[i]] = i; int b = INT_MAX, e = INT_MIN, j = 0; ll ans = 0; rep(len, 1, n+1) { while (j <= len/2) { j++; b = min(b, pos[n-j]); e = max(e, pos[n-j]); } int from = max(e-len+1, 0); int to = min(b, n-len) + 1; ans += max(to-from, 0); } cout << n*2+1 << ' ' << ans << '\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 37 38 39 40 41 42 43 44 45 46 47 48 49 | #define _USE_MATH_DEFINES #include <bits/stdc++.h> #ifdef LOC #include "debuglib.h" #else #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using Vi = vector<int>; using Pii = pair<int, int>; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(12); int n; cin >> n; Vi perm(n); each(p, perm) cin >> p, p--; Vi pos(n); rep(i, 0, n) pos[perm[i]] = i; int b = INT_MAX, e = INT_MIN, j = 0; ll ans = 0; rep(len, 1, n+1) { while (j <= len/2) { j++; b = min(b, pos[n-j]); e = max(e, pos[n-j]); } int from = max(e-len+1, 0); int to = min(b, n-len) + 1; ans += max(to-from, 0); } cout << n*2+1 << ' ' << ans << '\n'; return 0; } |