Submission #862509

#TimeUsernameProblemLanguageResultExecution timeMemory
862509blackslexSum Zero (RMI20_sumzero)C++17
61 / 100
296 ms34372 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 4e5 + 5; ll n, q, x, y, cur = -1, a[N], pref[N], par[N], dep[N], lf[N]; map<ll, ll> mp; void solve() { scanf("%lld %lld", &x, &y); ll ans = 0; x--; while (y && par[y] >= x) ans += (lf[y] >= x ? dep[y] - dep[lf[y]] : 1), y = (lf[y] >= x ? lf[y] : par[y]); printf("%lld\n", ans); } int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i]; dep[0] = 1; for (int i = 1; i <= n; i++) { if (!pref[i] || mp[pref[i]]) cur = max(cur, mp[pref[i]]); mp[pref[i]] = i; par[i] = cur; dep[i] = (~cur ? dep[par[i]] + 1 : 1); lf[i] = (~cur && dep[par[i]] - dep[lf[par[i]]] == dep[lf[par[i]]] - dep[lf[lf[par[i]]]] ? lf[lf[par[i]]] : par[i]); } scanf("%lld", &q); while (q--) solve(); }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:19:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   19 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i]; dep[0] = 1;
      |     ^~~
sumzero.cpp:19:86: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   19 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i]; dep[0] = 1;
      |                                                                                      ^~~
sumzero.cpp: In function 'void solve()':
sumzero.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%lld %lld", &x, &y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sumzero.cpp: In function 'int main()':
sumzero.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
sumzero.cpp:19:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i]; dep[0] = 1;
      |                                  ~~~~~^~~~~~~~~~~~~~~
sumzero.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%lld", &q);
      |     ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...