Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <cstring>
- #include <map>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e5 + 10;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<ll> v(n + 1);
- for(int i = 1; i <= n; i++) {
- cin >> v[i];
- }
- vector<ll> pref_sum(n + 1, 0);
- map<ll, ll> freq;
- freq[0]++;
- ll sum = 0;
- for(int i = 1; i <= n; i++) {
- if(i % 2 == 1) {
- sum += v[i];
- }
- else {
- sum -= v[i];
- }
- pref_sum[i] = sum;
- freq[sum]++;
- }
- ll res = 0;
- for(pair<ll, ll> p: freq) {
- if(p.second >= 2) {
- res += (p.second * (p.second - 1)) / 2;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment