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
#include <bits/stdc++.h>
using namespace std;
int sumy[126000];
int ciag[507];
unordered_map <int, int> sumy_1;
unordered_map <int, int> sumy_2;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> ciag[i];
        //ciag[i] = 0;
    }
    int iter = 0;
    for (int i = 0; i < n; ++i){
        int akt_suma = 0;
        for (int j = i; j < n; ++j){
            akt_suma += ciag[j];
            sumy[iter] = akt_suma;
            //cout << akt_suma << " ";
            iter++;
        }
    }
    //cout << "\n";
    long long wynik = 0;
    for (int i = 0; i < iter; ++i){
        wynik += (long long)sumy_2[0 - sumy[i]];
        //cout << "ROZPATRUJĘ: " << sumy[i] << "POTRZEBNE: " << 0 - sumy[i] << "MAM: " << sumy_2[0 - sumy[i]] << "\n";
        for (auto iter: sumy_1){
            sumy_2[sumy[i] + iter.first] += iter.second;
            //cout << "DODAJĘ: " << sumy[i] + iter.first << "\n";
        }
        sumy_1[sumy[i]]++;
    }
    cout << wynik << "\n";
}