# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
517004 | Stickfish | Sum Zero (RMI20_sumzero) | C++17 | 1073 ms | 44040 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 <iostream>
#include <map>
#include <vector>
using namespace std;
using ll = long long;
const int MAXN = 400000;
int a[MAXN];
vector<int> redg[MAXN];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
map<ll, int> mp;
mp[0] = -1;
ll psm = 0;
for (int i = 0; i < n; ++i) {
psm += a[i];
if (mp.find(psm) == mp.end()) {
a[i] = -2;
} else {
a[i] = mp[psm];
}
if (i && a[i - 1] > a[i])
a[i] = a[i - 1];
if (a[i] >= -1) {
redg[i].push_back(a[i]);
for (int j = 1;; ++j) {
int v = i;
for (int t = 0; t < 4; ++t) {
//cout << i << ' ' << j << ' ' << v << endl;
if (v == -1 || j - 1 >= redg[v].size()) {
v = -2;
break;
} else {
v = redg[v][j - 1];
}
}
if (v != -2)
redg[i].push_back(v);
else
break;
}
}
mp[psm] = i;
}
//return 0;
mp.clear();
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
--l;
int v = r - 1;
int ans = 0;
int j = 10;
while (true) {
if (v < l || j == -1)
break;
if (j >= redg[v].size() || redg[v][j] + 1 < l) {
--j;
} else {
ans += (1 << j) << j;
v = redg[v][j];
}
}
cout << ans << endl;
}
}
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... |