This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define int ll
using namespace std;
const int N = 4e5 + 3;
int a[N],p[N];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
p[i]=p[i-1]+a[i];
}
int q;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
int ans=0,R = l-1;
map <int,int> last;
last[p[l - 1]] = l - 1;
for (int i = l; i <= r; i++){
int k = last[p[i]];
if (k >= R) {
++ans;
R = i;
}
last[p[i]] = i;
}
cout<<ans<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |