Advertisement
Guest User

CDVR3.5

a guest
Nov 7th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int mxn = 2e5;
  4. //#define Kin
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.  
  11. #ifdef Kin
  12.     (void)!freopen("input.txt", "r", stdin);
  13.     (void)!freopen("output.txt", "w", stdout);
  14. #endif
  15.  
  16.     long long n, x;
  17.     cin >> n >> x;
  18.     long long sum = 0, count = 0;
  19.     map<long long, long long> mp;
  20.     mp[0]++;
  21.     while (n--)
  22.     {
  23.         long long a;
  24.         cin >> a;
  25.         sum += a;
  26.         count += mp[sum - x];
  27.         mp[sum]++;
  28.     }
  29.     if (count)
  30.         cout << count << '\n';
  31.     else
  32.         cout << -1;
  33.  
  34.     return 0;
  35. }
Tags: CDVR3.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement