제출 #537762

#제출 시각아이디문제언어결과실행 시간메모리
537762AdamGSSum Zero (RMI20_sumzero)C++17
61 / 100
526 ms24216 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #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, K=4; pair<ll,int>T[LIM]; int nxt[LIM][10], pot[11], n, q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; rep(i, n) { cin >> T[i+1].st; T[i+1].st+=T[i].st; T[i+1].nd=i+1; } stable_sort(T, T+n+1); rep(i, n+1) { if(T[i].st==T[i+1].st) { nxt[T[i].nd+1][0]=T[i+1].nd; } else nxt[T[i].nd+1][0]=n+1; } rep(i, 10) nxt[n+1][i]=n+1; for(int i=n; i; --i) { nxt[i][0]=min(nxt[i][0], nxt[i+1][0]); for(int j=1; j<10; ++j) { int akt=i; rep(l, K) { akt=nxt[akt][j-1]+1; if(akt==n+2) break; } nxt[i][j]=akt-1; } } pot[0]=1; for(int i=1; i<=10; ++i) pot[i]=pot[i-1]*K; int q; cin >> q; while(q--) { int l, r, ans=0; cin >> l >> r; for(int i=9; i>=0; --i) { while(nxt[l][i]<=r) { ans+=pot[i]; l=nxt[l][i]+1; } } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...