제출 #1070618

#제출 시각아이디문제언어결과실행 시간메모리
1070618AdamGSSum Zero (RMI20_sumzero)C++17
100 / 100
476 ms20440 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=50; pair<ll,int>T[LIM]; int nxt[LIM][3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; 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+2) nxt[i][0]=n+1; for(int i=1; i<=n; ++i) if(T[i].st==T[i-1].st) { nxt[T[i-1].nd][0]=T[i].nd; } for(int i=n; i>=0; --i) nxt[i][0]=min(nxt[i][0], nxt[i+1][0]); rep(k, 2) { rep(i, n+2) { int p=i; rep(j, K) p=nxt[p][k]; nxt[i][k+1]=p; } } int q; cin >> q; while(q--) { int l, r, ans=0; cin >> l >> r; --l; while(nxt[l][2]<=r) { l=nxt[l][2]; ans+=K*K; } while(nxt[l][1]<=r) { l=nxt[l][1]; ans+=K; } while(nxt[l][0]<=r) { l=nxt[l][0]; ans+=1; } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...