# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756510 | SlavicG | Sum Zero (RMI20_sumzero) | C++17 | 263 ms | 20128 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.
//not my code
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define pii pair<int,int>
using namespace std;
const int N = 4e5 + 1;
int jump[N], p[N], level[N];
unordered_map<ll, int> f;
main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n;
cin >> n;
ll tot = 0;
int mx = -1;
level[0] = 1;
for(int i = 1; i <= n; i++) {
int a; cin >> a;
tot += a;
if(f[tot] || !tot) mx = max(mx, f[tot]);
f[tot] = i;
p[i] = mx;
if(mx == -1) level[i] = 1;
else
level[i] = level[p[i]] + 1;
if(mx >= 0 && level[p[i]] - level[jump[p[i]]] == level[jump[p[i]]] - level[jump[jump[p[i]]]]) jump[i] = jump[jump[p[i]]];
else jump[i] = p[i];
}
int q;
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... |