Submission #1112624

#TimeUsernameProblemLanguageResultExecution timeMemory
1112624_callmelucianSum Zero (RMI20_sumzero)C++14
61 / 100
83 ms13640 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tpl; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int mn = 4e5 + 5; int nxt[mn], ans[mn], qryL[mn], qryR[mn], calc[2][mn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; map<ll,int> last; last[0] = 0, nxt[0] = -1; int nearest = -1; ll pre = 0; for (int i = 1; i <= n; i++) { ll a; cin >> a; pre += a; if (last.count(pre)) nearest = max(nearest, last[pre]); last[pre] = i, nxt[i] = nearest; } if (n > 100'000) return 0; int q; cin >> q; for (int i = 0; i < q; i++) { cin >> qryL[i] >> qryR[i]; qryL[i]--; } for (int s = 18; s >= 0; s--) { for (int i = 0; i <= n; i++) calc[0][i] = nxt[i]; for (int j = 1; j <= s; j++) { int t = j & 1; for (int i = 0; i <= n; i++) calc[t][i] = (calc[t ^ 1][i] == -1 ? -1 : calc[t ^ 1][calc[t ^ 1][i]]); } for (int i = 0; i < q; i++) if (qryL[i] <= calc[s & 1][qryR[i]]) ans[i] |= (1 << s), qryR[i] = calc[s & 1][qryR[i]]; } for (int i = 0; i < q; i++) cout << ans[i] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...