Submission #495485

#TimeUsernameProblemLanguageResultExecution timeMemory
495485couplefireSum Zero (RMI20_sumzero)C++17
61 / 100
663 ms21896 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 400005; int n, q, to[N][6]; map<ll, int> mp; ll sum; int main(){ // freopen("a.in", "r", stdin); cin.tie(0)->sync_with_stdio(0); cin >> n; mp[0] = 0; for(int i = 1; i<=n; ++i){ int a; cin >> a; sum += a; to[i][0] = to[i-1][0]; if(mp.count(sum)) to[i][0] = max(to[i][0], mp[sum]+1); mp[sum] = i; } for(int j = 1; j<6; ++j) for(int i = 1; i<=n; ++i) to[i][j] = to[max(to[max(to[max(to[i][j-1]-1, 0)][j-1]-1, 0)][j-1]-1, 0)][j-1]; cin >> q; while(q--){ int l, r; cin >> l >> r; int cnt = 0, cur = r; for(int i = 5; i>=0; --i) while(to[cur][i]>=l) cur = to[cur][i]-1, cnt += (1<<(2*i)); cout << cnt << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...