Advertisement
pb_jiang

ARC119C

Feb 3rd, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. // Problem: C - ARC Wrecker 2
  2. // Contest: AtCoder - AtCoder Regular Contest 119
  3. // URL: https://atcoder.jp/contests/arc119/tasks/arc119_c
  4. // Memory Limit: 1024 MB
  5. // Time Limit: 2000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  13. template <typename... Args> void logger(string vars, Args &&... values)
  14. {
  15.     cerr << vars << " = ";
  16.     string delim = "";
  17.     (..., (cerr << delim << values, delim = ", "));
  18.     cerr << endl;
  19. }
  20.  
  21. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  22. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  23. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  24. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  25.  
  26. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  27.  
  28. using ll = long long;
  29. using pii = pair<int, int>;
  30. using vl = vector<ll>;
  31. using vi = vector<int>;
  32.  
  33. int main(int argc, char **argv)
  34. {
  35.     int n;
  36.     cin >> n;
  37.     vi a(n);
  38.     for (auto &x : a)
  39.         cin >> x;
  40.     unordered_map<ll, int> s;
  41.     s[0] = 1;
  42.     ll flag = 1;
  43.     ll sum = 0;
  44.     ll cnt = 0;
  45.     for (auto x : a)
  46.         sum += flag * x, flag = -1 * flag, cnt += s[sum], s[sum] += 1;
  47.     cout << cnt << endl;
  48.     return 0;
  49. };
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement