Submission #624397

#TimeUsernameProblemLanguageResultExecution timeMemory
624397boris_mihovSum Zero (RMI20_sumzero)C++14
0 / 100
3 ms724 KiB
#include <unordered_map> #include <algorithm> #include <iostream> #include <cassert> #include <numeric> #include <vector> typedef long long llong; const int MAXN = 400000 + 10; const int MAXLOG = 10; const int BASE = 2; std::unordered_map < llong,int > cnt; int sparse[MAXLOG][MAXN]; int n, q; void buildSparse() { for (int log = 1 ; log <= MAXLOG-1 ; ++log) { sparse[log][0] = -1; for (int i = 1 ; i <= n ; ++i) { sparse[log][i] = i; for (int j = 1 ; j <= BASE ; ++j) { sparse[log][i] = sparse[log-1][sparse[log][i]]; if (sparse[log][i] == -1) break; } } } } int lifting(int from, int to) { int ans = 0; int pw = (1 << MAXLOG-1); for (int log = MAXLOG-1 ; log >= 0 ; --log) { while (sparse[log][from] >= to-1) { ans += pw; from = sparse[log][from]; } pw /= BASE; } return ans; } void solve() { int l, r; buildSparse(); std::cin >> q; for (int i = 1 ; i <= q ; ++i) { std::cin >> l >> r; std::cout << lifting(r, l) << '\n'; } } void read() { cnt[0] = 1; sparse[0][0] = -1; int curr; llong sum; std::cin >> n; for (int i = 1 ; i <= n ; ++i) { std::cin >> curr; sum += curr; sparse[0][i] = std::max(sparse[0][i-1], cnt[sum] - 1); cnt[sum] = i + 1; } } void fastIO() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIO(); read(); solve(); return 0; }

Compilation message (stderr)

sumzero.cpp: In function 'int lifting(int, int)':
sumzero.cpp:37:26: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   37 |     int pw = (1 << MAXLOG-1);
      |                    ~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...