제출 #643272

#제출 시각아이디문제언어결과실행 시간메모리
643272KriptonSum Zero (RMI20_sumzero)C++14
61 / 100
1090 ms16252 KiB
#include <bits/stdc++.h> using namespace std; unordered_map <long long,int> last; int best[400001][5]; int put[5]; bitset <400001> fraud; int main() { int n,x,i,j; long long s=0; cin>>n; put[0]=1; for(i=1;i<=4;i++) put[i]=16*put[i-1]; //cout<<put[4]<<'\n'; 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<=4;j++) for(i=0;i<=n;i++) { int start=i; for(int l=1;l<=8;l++) if(start!=-1&&best[start][j-1]!=-1) { best[i][j]=best[best[start][j-1]][j-1]; start=best[best[start][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=4; while(pas!=-1) { for(j=1;j<=15;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...