-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
39 lines (35 loc) · 992 Bytes
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define X first
#define Y second
#define rep(x, y, z) for(ll (z) = (x); (z) < (y); (z)++)
int constexpr N = 1e5;
int constexpr MOD = 1e9 + 7;
int constexpr INF = 1e9;
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin >> n;
vector<ll> in(n);
vector<ll> ps(n), psr(n);
rep (0, n, i) cin >> in[i];
partial_sum(all(in), ps.begin());
partial_sum(in.rbegin(), in.rend(), psr.begin());
if (ps[n - 1] % 3 != 0) return cout << 0, 0;
ll sum = ps[n - 1] / 3, cnt = 0;
vector<int> cntsr(n, 0);
cntsr[0] = psr[0] == sum ? 1 : 0;
rep (1, n, i) cntsr[i] = cntsr[i - 1] + (psr[i] == sum ? 1 : 0);
rep (0, n - 1, i) {
if (ps[i] == sum) {
cnt += cntsr[n - i - 2];
}
}
rep (0, n - 1, i) {
if (ps[i] == sum && ps[n - 1] - ps[i] == sum) cnt--;
}
cout << cnt;
return 0;
}