Submission #537760

#TimeUsernameProblemLanguageResultExecution timeMemory
537760AdamGSSum Zero (RMI20_sumzero)C++17
61 / 100
995 ms20508 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=100; pair<ll,int>T[LIM]; int nxt[LIM][3], 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, 3) nxt[n+1][i]=n+1; for(int i=n; i; --i) { nxt[i][0]=min(nxt[i][0], nxt[i+1][0]); int akt=i; rep(j, K) { akt=nxt[akt][0]+1; if(akt==n+2) break; } nxt[i][1]=akt-1; akt=i; rep(j, K) { akt=nxt[akt][1]+1; if(akt==n+2) break; } nxt[i][2]=akt-1; } int q; cin >> q; while(q--) { int l, r, ans=0; cin >> l >> r; while(nxt[l][2]<=r) { ans+=K*K; l=nxt[l][2]+1; } while(nxt[l][1]<=r) { ans+=K; l=nxt[l][1]+1; } while(nxt[l][0]<=r) { ++ans; l=nxt[l][0]+1; } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...