Submission #834837

#TimeUsernameProblemLanguageResultExecution timeMemory
834837LucaLucaMSum Zero (RMI20_sumzero)C++17
22 / 100
69 ms26572 KiB
#include <bits/stdc++.h> #warning That's the baby, that's not my baby typedef long long ll; using namespace std; const int NMAX = 4e5; const int QMAX = 4e5; vector<pair<int, int>>queries[QMAX + 1]; int answer[QMAX + 1]; ll sum[NMAX + 5]; const int p2[18] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072}; vector<int>g[NMAX + 1]; bitset<NMAX + 1>vis; int st[NMAX + 1]; int top; void dfs (int u) { vis[u] = true; st[++top] = u; // cout << u << " "; // cout << "! "; // for (int i = 1; i <= top; i++) { // cout << st[i] << ' '; // } // cout << '\n'; for (const auto &[pos, index] : queries[u]) { int l = 1, r = top; while (l < r) { int mid = (l + r) / 2; if (pos >= st[mid]) { r = mid; } else { l = mid + 1; } } // cout << "? " << st[top] << " - " << pos << '\n'; answer[index] = top - r; } for (const auto &v : g[u]) { if (!vis[v]) { dfs(v); } } top--; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> sum[i]; sum[i] += sum[i - 1]; } map<int, int>pos; int prv = n + 2; for (int i = n; i > 0; i--) { pos[sum[i]] = i; int nxt; if (!pos.count(sum[i - 1])) { nxt = n + 2; } else { nxt = pos[sum[i - 1]] + 1; } nxt = min(nxt, prv); prv = nxt; g[nxt].push_back(i); // cout << " " << nxt[i] << ' ' << i << '\n'; } int q; cin >> q; for (int i = 1; i <= q; i++) { int l, r; cin >> l >> r; queries[l].push_back({r + 1, i}); } for (int i = n + 2; i > 0; i--) { if (!vis[i]) { dfs(i); } } for (int i = 1; i <= q; i++) { cout << answer[i] << '\n'; } return 0; }

Compilation message (stderr)

sumzero.cpp:2:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    2 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...