This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |