fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. int n,x;
  17. cin >> n >> x;
  18.  
  19. vector<int>v(n+1);
  20. map<int,int>freq;
  21.  
  22. int ans = 0;
  23. for(int i = 1; i <= n; i++){
  24. cin >> v[i];
  25.  
  26. v[i] += v[i-1];
  27. }
  28.  
  29. for(int i = 0; i <= n; i++){
  30. ans += freq[v[i] - x];
  31. freq[v[i]]++;
  32. }
  33.  
  34. cout << ans;
  35. }
  36.  
  37.  
  38. signed main(){
  39. FastIO();
  40.  
  41. int t = 1;
  42. //cin >> t;
  43.  
  44. while (t--){
  45. solve();
  46. }
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5316KB
stdin
5 7
2 -1 3 5 -2
stdout
2