이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <map>
using namespace std;
int a[400005], l[400005][4], f[400005];
map<long long int, int> m;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
long long int n, c = 0;
cin >> n;
m[0] = 0;
f[0] = -1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
c += a[i];
f[i] = f[i - 1];
if (m.count(c)) {
f[i] = max(f[i], m[c]);
}
m[c] = i;
}
for (int i = 0; i <= n; i++) {
l[i][0] = f[i];
}
for (int i = 1; i <= 3; i++) {
for (int j = 0; j <= n; j++) {
int h = j;
for (int k = 0; k < 25; k++) {
if (h == -1 || l[h][i - 1] == -1) {
h = -1;
break;
}
else h = l[l[h][i - 1]][i - 1];
}
l[j][i] = h;
}
}
int q;
cin >> q;
for (int jj = 0; jj < q; jj++) {
int x, y, res = 0;
cin >> x >> y;
for (int i = 3; i >= 0; i--) {
if (y < x) break;
int c = 1;
for (int j = 1; j <= i; j++) c *= 25;
while (l[y][i] >= x - 1) {
y = l[y][i];
res += c;
}
}
cout << res << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |