subarray_sums_ii.cpp (602B)
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 void solve() 19 { 20 int n, x; 21 cin >> n >> x; 22 23 map<ll, int> a; 24 a[0] = 1; 25 ll lst = 0; 26 ll res = 0; 27 for (int i = 0; i < n; i++) { 28 int z; 29 cin >> z; 30 lst += z; 31 res += a[lst - x]; 32 a[lst]++; 33 } 34 35 cout << res << "\n"; 36 } 37 38 int main() 39 { 40 ios::sync_with_stdio(0); 41 cin.tie(0); 42 solve(); 43 }