This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,no-stack-protector,conserve-stack")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2")
#pragma GCC optimize("unroll-loops")
const int inf = 1e9 + 10;
const int mxn = 4e5 + 10;
const int base = 74;
const int LOG = 3;
long long pref;
map<long long, int> mp;
map<long long, int>::iterator it;
int stab[LOG][mxn], pw[LOG];
int main() {
int n, m;
cin >> n;
pw[0] = 1;
for(int i = 1; i < LOG; i++)
pw[i] = pw[i - 1] * base;
mp[0] = 0;
fill(stab[0], stab[0] + mxn, n + 1);
for(int i = 1, t; i <= n; i++) {
cin >> t;
pref += t;
it = mp.find(pref);
if(it != mp.end()) {
stab[0][it->second + 1] = i;
}
mp[pref] = i;
}
for(int i = n; i > 0; i--) {
stab[0][i] = min(stab[0][i], stab[0][i + 1]);
}
for(int j = 1; j < LOG; j++) {
fill(stab[j], stab[j] + mxn, n + 1);
for(int i = 1; i <= n; i++) {
int cur = stab[j - 1][i];
for(int b = 1; b < base; b++) {
cur = stab[j - 1][cur + 1];
}
stab[j][i] = cur;
}
}
cin >> m;
int l, r, ans;
while(m--) {
cin >> l >> r;
ans = 0;
for(int j = LOG - 1; j >= 0; j--) {
while(stab[j][l] <= r) {
l = stab[j][l] + 1;
ans += pw[j];
}
}
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |