fork download
  1. /**
  2.  * author: orzvanh14 ( )
  3.  * created: 23.12.2022 10:08:02
  4.  * too lazy to update time
  5. **/
  6. // i wants to take ioi
  7. //binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. #define int long long
  13. #define nn "\n"
  14. #define pi pair<int, int>
  15. #define fi first
  16. #define se second
  17. #define lb lower_bound
  18. #define ub upper_bound
  19. #define eb emplace_back
  20. #define pb push_back
  21. #define TASK " "
  22.  
  23. #define ms(a, x) memset(a, x, sizeof(a))
  24. #define all(a) a.begin(), a.end()
  25. #define All(a, n) a + 1, a + 1 + n
  26.  
  27. #define LOG 19
  28.  
  29.  
  30. const int INF = 1e18;
  31. const int mod = 1e9+7;
  32. const int N = 2e5 + 5;
  33. int MOD = 998244353;
  34. int bit[200000];
  35. struct node{
  36. int kc, u, hk;
  37. bool operator<(const node& other) const {
  38. return kc > other.kc;
  39. }
  40. };
  41. struct edge{
  42. int v, w, h;
  43. };
  44. int n;
  45. int ps[N];
  46. map<int, int> cnt;
  47. int ans = 0;
  48. void nhap(){
  49. cin >> n;
  50. for(int i = 1; i <= n; i++){
  51. int x; cin >> x;
  52. ps[i] = ps[i -1] + x;
  53. }
  54. }
  55. void solve(){
  56. cnt[0] = 1;
  57. for(int i = 1; i <= n; i++){
  58. int target = ps[i] -0;
  59. ans += cnt[target];
  60. cnt[ps[i]]++;
  61. }
  62. cout << ans << nn;
  63. }
  64. signed main() {
  65. // freopen("piggyback.in", "r", stdin);
  66. // freopen("piggyback.out", "w", stdout);
  67. ios_base::sync_with_stdio(0);
  68. cin.tie(0);
  69. cout.tie(0);
  70. nhap();
  71. solve();
  72. return (0 ^ 0);
  73.  
  74. }
  75.  
  76.  
Success #stdin #stdout 0.01s 5552KB
stdin
6
-6 0 1 2 3 -6
stdout
4