Submission #857711

#TimeUsernameProblemLanguageResultExecution timeMemory
857711alexdumitruSum Zero (RMI20_sumzero)C++14
100 / 100
235 ms13648 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 4e5; int nxt[1 + kN], jump[1 + kN + 1 + 1]; int64_t sum[1 + kN]; int L[1 + kN], R[1 + kN], ANS[1 + kN]; void testCase() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> sum[i]; sum[i] += sum[i - 1]; } multiset<int64_t> sums{0}; int r = 0; for (int l = 1; l <= n; ++l) { while (r <= n) { if (sums.count(sum[r]) >= 2) { break; } r += 1; sums.emplace(sum[r]); } nxt[l] = r + 1; sums.erase(sums.find(sum[l - 1])); } int Q; cin >> Q; for (int i = 1; i <= Q; ++i) { cin >> L[i] >> R[i]; ANS[i] = 0; } jump[n + 1] = jump[n + 2] = n + 2; for (int j = log2(n); j >= 0; --j) { for (int i = 1; i <= n; ++i) { jump[i] = nxt[i]; } for (int rep = 1; rep <= j; ++rep) { for (int i = 1; i <= n; ++i) { jump[i] = jump[jump[i]]; } } for (int i = 1; i <= Q; ++i) { if (jump[L[i]] <= R[i] + 1) { ANS[i] += (1 << j); L[i] = jump[L[i]]; } } } for (int i = 1; i <= Q; ++i) { cout << ANS[i] << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tests = 1; for (int tc = 1; tc <= tests; ++tc) { testCase(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...