Submission #857704

#TimeUsernameProblemLanguageResultExecution timeMemory
857704alexdumitruSum Zero (RMI20_sumzero)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int NMAX = 400005; const int LMAX = 20; int n, q, a[NMAX], Next[NMAX], jump[NMAX]; long long sp[NMAX]; int L[NMAX], R[NMAX], ANS[NMAX]; void solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; Next[n + 1] = Next[n + 2] = n + 2; multiset<int64_t> sums{0}; int r = 0; long long suml = 0; long long sumr = 0; for(int l = 1; l <= n; ++l) { while (r <= n) { if (sums.count(sumr) >= 2) break; r++; sumr += a[r]; sums.emplace(sumr); } Next[l] = r + 1; sums.erase(sums.find(suml)); suml += a[i]; } cin >> q; for(int i = 1; i <= q; i++) cin >> L[i] >> R[i]; for(int lg = log2(n + 1); lg >= 0; lg--) { for(int i = 1; i <= n + 2; i++) jump[i] = Next[i]; for(int k = 1; k <= lg; k++) for(int i = 1; i <= n + 2; i++) jump[i] = jump[jump[i]]; for(int i = 1; i <= q; i++) if(jump[L[i]] <= R[i] + 1) { ANS[i] += (1 << lg); L[i] = jump[L[i]]; } } for(int i = 1; i <= q; i++) cout << ANS[i] << '\n'; } int main() { ios_base :: sync_with_stdio(0); cin.tie(0); solve(); return 0; }

Compilation message (stderr)

sumzero.cpp: In function 'void solve()':
sumzero.cpp:34:19: error: 'i' was not declared in this scope
   34 |         suml += a[i];
      |                   ^