제출 #537732

#제출 시각아이디문제언어결과실행 시간메모리
537732AdamGSSum Zero (RMI20_sumzero)C++17
0 / 100
13 ms468 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=500; ll T[LIM]; map<ll,int>mp; int nxt[LIM][2], n, q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; rep(i, n) { cin >> T[i+1]; T[i+1]+=T[i]; } for(int i=n; i; --i) { mp[T[i]]=i; if(mp[T[i-1]]) nxt[i][0]=mp[T[i-1]]; else nxt[i][0]=n+1; } nxt[n+1][0]=nxt[n+1][1]=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+1) { ++akt; break; } } nxt[i][1]=akt-1; } int q; cin >> q; while(q--) { int l, r, ans=0; cin >> l >> r; 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...