제출 #456485

#제출 시각아이디문제언어결과실행 시간메모리
456485AdamGSSum Zero (RMI20_sumzero)C++14
61 / 100
459 ms24984 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=4e5+7; int nxt[LIM][8], pot[8]; map<ll,ll>mp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); pot[0]=1; for(int i=1; i<8; ++i) pot[i]=pot[i-1]*5; int n; cin >> n; ll sum=0; rep(i, n) { cin >> nxt[i+1][0]; sum+=nxt[i+1][0]; } for(int i=n; i>=0; --i) { ll a=nxt[i][0]; nxt[i][0]=0; if(!mp[sum]) nxt[i][0]=n+1; else nxt[i][0]=mp[sum]; mp[sum]=i; sum-=a; if(i<n) nxt[i][0]=min(nxt[i][0], nxt[i+1][0]); } mp.clear(); rep(i, 8) nxt[n+1][i]=n+1; for(int j=1; j<8; ++j) { rep(i, n+1) nxt[i][j]=nxt[nxt[nxt[nxt[nxt[i][j-1]][j-1]][j-1]][j-1]][j-1]; } int q; cin >> q; while(q--) { int l, r; cin >> l >> r; --l; int ans=0, i=7; while(i>=0) { if(nxt[l][i]<=r) { ans+=pot[i]; l=nxt[l][i]; } else --i; } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...