#include<bits/stdc++.h>
using namespace std;
using lld = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> t(n);
for(int& i : t)
cin >> i;
vector<int> pos(n);
for(int i=0;i<n;i++)
pos[t[i]-1] = i;
lld res = 0;
int l=n,r=-1;
for(int i=1;i<=n;i++) {
l = min(l, pos[n-i/2-1]), r = max(r, pos[n-i/2-1]);
int x = max(0, r-i+1), y = min(n-1, l+i-1)-i+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 | #include<bits/stdc++.h> using namespace std; using lld = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> t(n); for(int& i : t) cin >> i; vector<int> pos(n); for(int i=0;i<n;i++) pos[t[i]-1] = i; lld res = 0; int l=n,r=-1; for(int i=1;i<=n;i++) { l = min(l, pos[n-i/2-1]), r = max(r, pos[n-i/2-1]); int x = max(0, r-i+1), y = min(n-1, l+i-1)-i+1; res += max(0, y-x+1); } cout << 2*n+1 << " " << res << "\n"; return 0; } |
English