# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
902066 | Isam | Izbori (COCI22_izbori) | C++17 | 72 ms | 2648 KiB |
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;
int N, A[200005];
long long pref[200005];
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
for(register int i = 1; i <= N; ++i) cin >> A[i];
if(N < 3000){
int cur_dom(0), ans(0);
for(int i = 1; i <= N; ++i){
map<int, int> mp;
for(register int j = i; j <= N; ++j){
mp[A[j]]++;
if(mp[A[j]] > mp[cur_dom]) cur_dom = A[j];
ans += (mp[cur_dom] > ((j - i + 1) / 2));
}
}
cout << ans << '\n';
}else{
for(register int i = 1; i <= N; ++i) A[i] = (A[i] == 1 ? 1 : -1), pref[i] = pref[i - 1] + A[i];
map<int, int> mp;
long long ans(0);
for(register int i = 1; i <= N; ++i){
mp[pref[i]]++;
ans += mp[pref[i]];
}
cout << ans << '\n';
}
return 0;
}
/*
1 1 2 1 2
-1 -1 1 -1 1
abs(pref[r] - pref[l]) >= 1;
pref[r] != pref[l]
ans = n * (n + 1) / 2 - regular_brackets
*/
Compilation message (stderr)
# | 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... |