This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Ai_2007
//Make the impossible possible
#include<bits/stdc++.h>
#define ll long long
#define fo(i,m,n) for(int i=m; i<=n; i++)
#define fod(i,m,n) for(int i=m; i>=n; i--)
#define fi first
#define se second
#define Nmax 1000001
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N=4e5+5;
int n,q,a[N];
//map<ll,vector<int>> m;
ll cur=0;
void solve()
{
    cin>>n;
    fo(i,1,n) cin>>a[i];
    cin>>q;
    fo(i,1,q){
        int l,r,ans=0;
        cin>>l>>r;
        cur=0;
        set<ll> s;
        s.insert(0);
       fo(j,l,r){
           cur+=a[j];
           if(s.find(cur)!=s.end()){
                ans++;
                s.clear();
                s.insert(0);
                cur=0;
           }
           else s.insert(cur);
       }
       cout<<ans<<"\n";
    }
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}
Compilation message (stderr)
sumzero.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main()
      | ^~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |