subarray_divisibility.cpp (621B)
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 using ui = unsigned int; 6 using l = long; 7 using ul = unsigned long; 8 using ll = long long; 9 using ull = unsigned long long; 10 11 using vi = vector<int>; 12 using vui = vector<ui>; 13 using vl = vector<l>; 14 using vul = vector<ul>; 15 using vll = vector<ll>; 16 using vull = vector<ull>; 17 18 19 20 void solve() 21 { 22 int n; 23 cin >> n; 24 25 map<ll, int> a; 26 a[0] = 1; 27 ll lst = 0; 28 ll res = 0; 29 for (int i = 0; i < n; i++) { 30 int z; 31 cin >> z; 32 lst += z; 33 lst = (n + (lst % n)) % n; 34 res += a[lst]; 35 a[lst]++; 36 } 37 38 cout << res << "\n"; 39 } 40 41 int main() 42 { 43 ios::sync_with_stdio(0); 44 cin.tie(0); 45 solve(); 46 }