fork(1) download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. int k=-10;
  15. vector<int>a={10, 2, -2, -20, 10};
  16. int n=a.size();
  17. map<int,int>mp;
  18. mp[0]=1;
  19. vector<int>p(n,0);
  20. int count=0;
  21. p[0]=a[0];
  22. for(int i=1;i<n;i++){
  23. p[i]=p[i-1]+a[i];
  24. if(mp.find(p[i]-k)!=mp.end()){
  25. count+=mp[p[i]-k];
  26. }
  27. mp[p[i]]++;
  28. }
  29.  
  30. cout<<count<<endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
2