# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1136819 | Wendidiask | Sum Zero (RMI20_sumzero) | C++20 | 28 ms | 63040 KiB |
/*
:---:--:--::::::--:-:----:
::-:::. ::-:::
.* -===.. :---
.-+*##=-------====-: :--:
:+##=.* -= :=+- .-=:
.+++-. :- -=. .=+- .--.
.++=- + -= :*- :-.
+*+- :- -=. -*: :=:
#*: * -=. +- .=
=:%+ -: -=. +- --
-%: * -=. *: +.
:%-.. =. -=. # -:
:=# .. + -=. == -=
---+ . = -=. .# .+
-: == . = :------::------:.-=. % .=
:- == .=. ---:. :--#+. .% :-
= .* .+.. :=- :++ -+ =:
+ #. + -=: :*%-*: *
:= :# :=:= . :-----: =+-+ .+
* -* *=- . .- :::::::. :* .#+. +
:- -+ :#. --::-----: :* ++= .-
+ :*. *. .:::::*%: ++ +.-=. +
+ -#**----: .= -*. + -= =
* +.#=+: + . .=+: =. -=. =
= -+ :++: + .. .=+= .= -=. -
= %- :====-:. =. .:--===- * -=. -
+ +-- .:--==#==-:.= + -=. =
* + * =. : .= -=. =
+ = * + = -=. +
:- = .= =: = -=. .-
* + =: * * -=. +
:- .+ =- :- .+ -=. .+
* * := * := -= *
= :- =: .- .=: -=. =:
-: * .=- + .=- -= :-
=: -: --: :- :--: -=. .=
=:+ ----. * :---. -= .+
--=*----------------------=*+=--=+--=+*+------------------------------------------------%+:.
:: := +:- -- :.
.=. =.
-= -=
.=: .=.
.=: .+:
:-- :-:
-- -=.
:--. --:
:--: .--:
.-:-: ::--.
:----. .:----
.:::::::::-::::::--::::::::.
*/
// Hello this is Tyx2019's clone
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cerr << #x << " is " << x << "\n"
#define hehe ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repb(i, a, b) for (int i = b; i >= a; i--)
#define pii pair<int, int>
#define linebreak cout << "---------------------------------------------------------\n"
#define f first
#define s second
#define pb push_back
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// good luck
const int MS = 4e5+5, mod = 1e9+9, INF = 3e18, blk = 400;
int n, a[MS], pref[MS], twok[MS][20];
map<int, int> m;
int32_t main() {
hehe
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
pref[0] = 0;
for (int i = 1; i <= n; i++) pref[i] = pref[i-1]+a[i];
for (int i = 1; i <= n; i++) m[pref[i]] = -1;
m[0] = 0; int macs = 0;
memset(twok, -1, sizeof(twok));
for (int i = 1; i <= n; i++) {
if (m[pref[i]] == -1) {
m[pref[i]] = i; continue;
}
for (int j = macs+1; j <= m[pref[i]]+1; j++) {
if (twok[j][0] == -1 or twok[j][0] > i) {
twok[j][0] = i+1;
}
}
macs = m[pref[i]]+1;
m[pref[i]] = i;
}
for (int k = 0; k < 19; k++) {
for (int i = 1; i <= n; i++) {
if (twok[i][k] == -1 or twok[i][k] == n+1) twok[i][k+1] = -1;
else twok[i][k+1] = twok[twok[i][k]][k];
}
}
int q; cin >> q;
while (q--) {
int l, r, res = 0; cin >> l >> r;
for (int k = 19; k >= 0; k--) {
if (twok[l][k]-1 <= r and twok[l][k] != -1) {
l = twok[l][k]; res += (1<<k);
}
}
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... |