This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mxN = (int)3e5 +5;
signed main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
int n; cin>>n;
vector<int>v(n);
bool ok = 0;
for(auto &z : v) {
cin>>z;
if(z == 3)
ok = 1;
z = z == 1 ? -1 : 1;
}
if(ok) {
cout << 10; return 0;
}
int curr = mxN;
vector<int>p(4*mxN,0);
int64_t ans = 0, d = 0;
for(int i = 0 ; i < n ; i++) {
if(v[i] == 1) {
p[++curr]++;
d += p[curr];
} else {
p[curr+1]++;
d -= p[curr--];
}
ans += d;
}
p.clear();
p.resize(4*mxN,0);
curr = mxN;
int64_t ans2 = 0;
d = 0;
for(int i = 0 ; i < n ; i++) {
if(v[i] == -1) {
p[++curr]++;
d += p[curr];
} else {
p[curr+1]++;
d -= p[curr--];
}
ans2 += d;
}
cout << ans + ans2;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |