제출 #942695

#제출 시각아이디문제언어결과실행 시간메모리
942695socpiteSum Zero (RMI20_sumzero)C++14
100 / 100
694 ms19428 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 4e5+5; const int step = 74; int n; pair<long long, int> A[maxn]; int mx[maxn], mx_b[maxn], mx_b2[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; memset(mx, -1, sizeof(mx)); for(int i = 1; i <= n; i++){ cin >> A[i].first; A[i].first += A[i-1].first; A[i].second = i; } sort(A, A+n+1); for(int i = 1; i <= n; i++){ if(A[i].first == A[i-1].first)mx[A[i].second] = A[i-1].second; } for(int i = 0; i <= n; i++){ if(i)mx[i] = max(mx[i], mx[i-1]); mx_b[i] = i; for(int j = 0; j < step; j++){ if(mx_b[i] == -1)break; mx_b[i] = mx[mx_b[i]]; } mx_b2[i] = i; for(int j = 0; j < step; j++){ if(mx_b2[i] == -1)break; mx_b2[i] = mx_b[mx_b2[i]]; } } int q; cin >> q; while(q--){ int l, r, ans = 0; cin >> l >> r; while(mx[r] >= l-1){ if(mx_b2[r] >= l-1){ r = mx_b2[r]; ans += step*step; } if(mx_b[r] >= l-1){ r = mx_b[r]; ans += step; } if(mx[r] >= l-1){ r = mx[r]; ans++; } } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...