제출 #861946

#제출 시각아이디문제언어결과실행 시간메모리
861946imarnSum Zero (RMI20_sumzero)C++14
0 / 100
4 ms2652 KiB
#include<bits/stdc++.h> //#include "insects.h" #define f first #define s second #define pb push_back #define pii pair<int,int> #define ll long long using namespace std; const int N=4e5+5; int pr[N][20]{0}; unordered_map<ll,int>dp; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); int n;cin>>n;ll a[n+1]; for(int i=1;i<=n;i++)cin>>a[i]; ll sum=0;for(int i=0;i<=n+1;i++)pr[i][0]=i; int id=0; dp[0]=0; for(int i=1;i<=n;i++){ sum+=a[i]; if(dp.find(sum)!=dp.end()){ while(id<=dp[sum]){ pr[id++][0]=i; }dp[sum]=0; }dp[sum]=i; }pr[n][0]=n+1; for(int j=1;j<20;j++)for(int i=0;i<=n;i++)pr[i][j]=pr[pr[i][j-1]][j-1]; int q;cin>>q; while(q--){ int st,ed;cin>>st>>ed;st--; int l=0,r=n; while(l<r){ int m=(l+r)>>1; int x=m;int i=0; int cur=st; while(x>0){ if(x&1)cur=pr[cur][i]; i++;x>>=1; } if(cur>ed)r=m; else l=m+1; }int cur=0;int i=0,x=l; while(x>0){ if(x&1)cur=pr[cur][i]; i++;x>>=1; }cout<<l-1<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...