제출 #456486

#제출 시각아이디문제언어결과실행 시간메모리
456486AdamGSSum Zero (RMI20_sumzero)C++14
61 / 100
373 ms21032 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]; pair<ll,int>T[LIM]; 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+1) nxt[i][0]=n+1; rep(i, n) { ll a; cin >> a; sum+=a; T[i+1]={sum, i+1}; } sort(T, T+n+1); rep(i, n) { if(T[i].st==T[i+1].st) nxt[T[i].nd][0]=T[i+1].nd; } for(int i=n-1; i>=0; --i) nxt[i][0]=min(nxt[i][0], nxt[i+1][0]); 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...