#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, l, r, d, i, t; unsigned long long s; vector<int> a; cin >> n; a.reserve(n); for(i=0;i<n;++i) { cin >> t; a[n-t] = i; } s = 0, l = r = a[0]; for(d=1;d<=n;++d) { if(d%2==0) l = min(l, a[d/2]), r=max(r,a[d/2]); // cerr << d << ' ' << l << ' ' << r << ' ' << d-r+l << ' ' << l+1 << ' ' << n-r << ' ' << n-d+1 << endl; s += max(0, min({d-r+l, l+1, n-r, n-d+1})); } cout << n*2+1 << ' ' << s << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, l, r, d, i, t; unsigned long long s; vector<int> a; cin >> n; a.reserve(n); for(i=0;i<n;++i) { cin >> t; a[n-t] = i; } s = 0, l = r = a[0]; for(d=1;d<=n;++d) { if(d%2==0) l = min(l, a[d/2]), r=max(r,a[d/2]); // cerr << d << ' ' << l << ' ' << r << ' ' << d-r+l << ' ' << l+1 << ' ' << n-r << ' ' << n-d+1 << endl; s += max(0, min({d-r+l, l+1, n-r, n-d+1})); } cout << n*2+1 << ' ' << s << '\n'; } |