Submission #862528

#TimeUsernameProblemLanguageResultExecution timeMemory
862528blackslexSum Zero (RMI20_sumzero)C++17
0 / 100
1 ms600 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; ll n, q, x, y, cur = -1, a; unordered_map<ll, ll> mp; void solve(vector<ll> &par, vector<ll> &dep, vector<ll> &lf) { 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); vector<ll> par(n + 5, 0), dep(n + 5, 0), lf(n + 5, 0); dep[0] = 1; for (int i = 1; i <= n; i++) { scanf("%lld", &x); a += x; if (!a || mp[a]) cur = max(cur, mp[a]); mp[a] = 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(par, dep, lf); }

Compilation message (stderr)

sumzero.cpp: In function 'void solve(std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)':
sumzero.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%lld %lld", &x, &y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sumzero.cpp: In function 'int main()':
sumzero.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
sumzero.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%lld", &x); a += x;
      |         ~~~~~^~~~~~~~~~~~
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...