Submission #643278

#TimeUsernameProblemLanguageResultExecution timeMemory
643278KriptonSum Zero (RMI20_sumzero)C++14
61 / 100
618 ms25080 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; pair <long long,int> sum[400001]; int last[400001]; int best[400001][5]; int put[5]; bitset <400001> fraud; int main() { ios_base::sync_with_stdio; cin.tie(NULL); cout.tie(NULL); 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; sum[i]={s,i}; } sort(sum,sum+n+1); last[sum[0].second]=-1; for(i=1;i<=n;i++) if(sum[i].first==sum[i-1].first) last[sum[i].second]=sum[i-1].second; else last[sum[i].second]=-1; for(i=1;i<=n;i++) { best[i][0]=best[i-1][0]; fraud[i]=1; if(last[i]>best[i][0]) { best[i][0]=last[i]; fraud[i]=0; } last[i]=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; }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:11:15: warning: statement is a reference, not call, to function 'std::ios_base::sync_with_stdio' [-Waddress]
   11 |     ios_base::sync_with_stdio;
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~
sumzero.cpp:11:15: warning: statement has no effect [-Wunused-value]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...