Submission #875148

#TimeUsernameProblemLanguageResultExecution timeMemory
875148Ahmed57Sum Zero (RMI20_sumzero)C++17
100 / 100
963 ms19164 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") int P[400001][5];int vl[5]; int xd = 5; int main(){ ios_base::sync_with_stdio(false);cin.tie(0); vl[0] = 1; for(int i = 1;i<xd;i++){ vl[i] = 5*vl[i-1]; } int n,l,r,ans,x; cin>>n; unordered_map<long long,int> mp; long long sum = 0; mp[0] = 1; for(int i = 0;i<n;i++){ cin>>x; sum+=x; if(mp[sum]>0){ P[mp[sum]-1][0] = i+1; } mp[sum] = i+2; } for(int i = 0;i<=n;i++){ if(P[i][0]==0)P[i][0] = n; else P[i][0]--; } for(int i = n;i>=0;i--){ if(i<n)P[i][0] = min(P[i][0],P[i+1][0]); for(int j = 1;j<xd;j++){ P[i][j] = P[min(n,P[min(n,P[min(n,P[min(n,P[i][j-1]+1)][j-1]+1)][j-1]+1)][j-1]+1)][j-1]; } } int q;cin>>q; while(q--){ cin>>l>>r;l--;r--; ans = 0; int e = xd-1; while(e>=0){ while(P[l][e]<=r){ l = P[l][e]+1; ans+=vl[e]; } e--; } cout<<ans<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...