Submission #643259

#TimeUsernameProblemLanguageResultExecution timeMemory
643259KriptonSum Zero (RMI20_sumzero)C++14
61 / 100
1085 ms30228 KiB
#include <bits/stdc++.h> using namespace std; map <long long,int> last; int best[400001][8]; int put[8]; bitset <400001> fraud; int main() { int n,x,i,j; long long s=0; cin>>n; put[0]=1; for(i=1;i<=7;i++) put[i]=6*put[i-1]; best[0][0]=-1; for(i=1;i<=n;i++) { cin>>x; s+=x; best[i][0]=best[i-1][0]; fraud[i]=1; if((s==0||last[s])&&last[s]>best[i][0]) { best[i][0]=last[s]; fraud[i]=0; } last[s]=i; } for(j=1;j<=7;j++) for(i=0;i<=n;i++) if(best[i][j-1]!=-1&&best[best[i][j-1]][j-1]!=-1&&best[best[best[i][j-1]][j-1]][j-1]!=-1&&best[best[best[best[i][j-1]][j-1]][j-1]][j-1]!=-1&&best[best[best[best[best[i][j-1]][j-1]][j-1]][j-1]][j-1]!=-1&&best[best[best[best[best[best[i][j-1]][j-1]][j-1]][j-1]][j-1]][j-1]!=-1) best[i][j]=best[best[best[best[best[best[i][j-1]][j-1]][j-1]][j-1]][j-1]][j-1]; else best[i][j]=-1; int q,a,b; cin>>q; for(i=1;i<=q;i++) { cin>>a>>b; if(best[b][0]==-1) { cout<<"0\n"; continue; } int rez=0; if(fraud[b]) { b=best[b][0]; rez=1; } if(b<a-1) { cout<<"0\n"; continue; } int start=b,pas=7; while(pas!=-1) { for(j=1;j<=5;j++) if(best[start][pas]>=a-1) { rez+=put[pas]; start=best[start][pas]; } pas--; } cout<<rez<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...