Submission #942694

#TimeUsernameProblemLanguageResultExecution timeMemory
942694socpiteSum Zero (RMI20_sumzero)C++14
61 / 100
1030 ms11676 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 4e5+5; const int step = 640; int n; pair<long long, int> A[maxn]; int mx[maxn], mx_b[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]]; } } int q; cin >> q; while(q--){ int l, r, ans = 0; cin >> l >> r; while(mx[r] >= l-1){ 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...