Submission #859421

#TimeUsernameProblemLanguageResultExecution timeMemory
859421DenkataSum Zero (RMI20_sumzero)C++14
0 / 100
7 ms8796 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int maxn = 4e5+3; const int base = 100; const int maxlog = 3; int sparse[maxlog][maxn]; int i,j,p,q,n,m,k,a[maxn],Q,closest[maxn],st[3],l,r; long long pref[maxn]; map <long long,int> enc; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; st[0] = 1; st[1] = base; st[2] = base*base; for(i=1; i<=n; i++) cin>>a[i]; for(i=1; i<=n; i++) { pref[i] = pref[i-1]+a[i]; sparse[0][i] = max(sparse[0][i-1],enc[pref[i]]); if(pref[i]==0) sparse[0][i] = max(sparse[0][i],1); enc[pref[i]] = i; // cout<<sparse[0][i]<<endl; } for(i=1; i<maxlog; i++) { for(k=1; k<=n; k++) { sparse[i][k] = sparse[i-1][k]; for(j=1;sparse[i][k]!=0 && j<base; j++) sparse[i][k] = sparse[i-1][sparse[i][k]]-1; } } cin>>Q; for(i=1; i<=Q; i++) { cin>>l>>r; int ans = 0; for(j=maxlog-1; j>=0; j--) { //cout<<j<<" "<<r<<" "<<sparse[j][r]<<endl; while(sparse[j][r]>=l) { ans+=st[j]; r = sparse[j][r]; } } cout<<ans<<endl; } return 0; } /** 10 1 2 -3 0 1 -4 3 2 -1 1 3 1 10 1 5 2 9 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...