#include <iostream>
#include <cstring>
#include <map>
using namespace std;
#define ll long long
int n;
ll ways = 0;
ll arr[200005];
ll 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 << (ll)((n + 1) * n) / 2 - ways;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
2376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |