이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |