# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
857063 | chanhchuong123 | Sum Zero (RMI20_sumzero) | C++14 | 922 ms | 23696 KiB |
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;
#define task ""
const int MAX = 400004;
const int base = 128;
int n, q;
int pw[2];
int c[MAX];
int sf = 0;
int ans[MAX];
int jump[2][MAX];
map<int, int> last;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> c[i];
}
for (int i = 1; i <= n + 2; ++i) {
jump[0][i] = n + 2;
jump[1][i] = n + 2;
}
last[0] = n + 1;
for (int i = n; i >= 1; --i) {
sf += c[i];
jump[0][i] = min(jump[0][i], jump[0][i + 1]);
if (last[sf] > 0) jump[0][i] = min(jump[0][i], last[sf]); last[sf] = i;
}
pw[0] = 1; pw[1] = base;
for (int j = 1; j <= 1; ++j) {
for (int i = 1; i <= n + 1; ++i) {
jump[j][i] = i;
for (int k = 1; k <= base; ++k)
jump[j][i] = jump[j - 1][jump[j][i]];
}
}
cin >> q;
while (q--) {
int l, r, res = 0; cin >> l >> r;
for (int j = 1; j >= 0; --j) {
while (jump[j][l] - 1 <= r) {
l = jump[j][l];
res += pw[j];
}
}
cout << res << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |