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 <iostream>
#include <cstring>
#include <map>
using namespace std;
#define ll long long
int n;
ll ways = 0;
int arr[200005];
int psum[200005];
int highest = 0;
map<int, int> s;
map<int, int>::iterator it;
int main(){
cin >> n;
for(int i = 0; i < n; i++) cin >> arr[i];
if(arr[0] == 1){
psum[0] = 1;
s[psum[0]]++;
}
else{
psum[0] = -1;
s[psum[0]]++;
}
for(int i = 1; i < n; i++){
if(arr[i] == 1)psum[i] = 1;
else psum[i] = -1;
psum[i] += psum[i - 1];
s[psum[i - 1]]++;
ways += s[-1 * psum[i]];
}
cout << (int)((n + 1) * n) / 2 - ways;
}
# | 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... |