| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1319904 | sonarcht | Sum Zero (RMI20_sumzero) | C++20 | 1097 ms | 24312 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(v) begin(v), end(v)
#define pll pair<ll, ll>
#define fi first
#define se second
#define vll vector<ll>
#define mll map<ll, ll>
mt19937_64 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
const ll N = 4e5 + 6, inf = 1e18 + 7, mod = 1e9 + 7;
ll n, m, k, q, ans, a[N], pf[N], jump1[N], jump2[N];
mll mp;
void solve() {
cin >> n;
ll B = sqrt(n);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) pf[i] = pf[i-1] + a[i];
fill(jump1, jump1 + N, n+2);
for (int i = n; i >= 1; --i) {
mp[pf[i]] = i+1;
if (mp.count(pf[i-1])) jump1[i] = mp[pf[i-1]];
jump1[i] = min(jump1[i], jump1[i+1]);
}
for (int i = 1; i <= n; ++i) {
ll u = i;
for (int j = 1; j <= B; ++j) u = jump1[u];
jump2[i] = u;
}
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
ll u = l, ans = 0;
while (u <= n && jump2[u] <= r+1) {
ans += B;
u = jump2[u];
}
while (u <= n && jump1[u] <= r+1) {
++ans;
u = jump1[u];
}
cout << ans << endl;
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
ll tc = 1;
// cin >> tc;
while (tc--) {
solve();
}
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... | ||||
