#include <bits/stdc++.h>
using namespace std;
const int kN = 4e5;
int a[1 + kN], sum[1 + kN], nxt[1 + kN], jump[1 + kN + 1 + 1];
struct query {
int l, r, ans;
} q[1 + kN];
void testCase() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
multiset<int64_t> sums{0};
int r = 0;
for (int l = 1; l <= n; ++l) {
while (r <= n) {
if (sums.count(sum[r]) >= 2) {
break;
}
r += 1;
sums.emplace(sum[r]);
}
nxt[l] = r + 1;
sums.erase(sums.find(sum[l - 1]));
}
int Q;
cin >> Q;
for (int i = 1; i <= Q; ++i) {
cin >> q[i].l >> q[i].r;
q[i].ans = 0;
}
jump[n + 1] = jump[n + 2] = n + 2;
for (int j = log2(n); j >= 0; --j) {
for (int i = 1; i <= n; ++i) {
jump[i] = nxt[i];
}
for (int rep = 1; rep <= j; ++rep) {
for (int i = 1; i <= n; ++i) {
jump[i] = jump[jump[i]];
}
}
for (int i = 1; i <= Q; ++i) {
if (jump[q[i].l] <= q[i].r + 1) {
q[i].ans += (1 << j);
q[i].l = jump[q[i].l];
}
}
}
for (int i = 1; i <= Q; ++i) {
cout << q[i].ans << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 1; tc <= tests; ++tc) {
testCase();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
3928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
93 ms |
32376 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |