Submission #597327

#TimeUsernameProblemLanguageResultExecution timeMemory
597327pedroslreySum Zero (RMI20_sumzero)C++17
61 / 100
330 ms65536 KiB
#include <bits/stdc++.h> using namespace std; using lli = long long; const int MAXN = 8e5 + 10; const int MAXK = 30; int ant[MAXN]; int dp[MAXN][MAXK]; int main() { int n; cin >> n; map<lli, vector<int>> mp; mp[0].push_back(0); lli sum = 0; for (int i = 1; i <= n; ++i) { int x; cin >> x; sum += x; mp[sum].push_back(i); } for (int i = 1; i <= n; ++i) ant[i] = -1; for (auto [k, xs]: mp) for (int i = 1; i < xs.size(); ++i) ant[xs[i]] = xs[i-1]; for (int k = 0; k < MAXK; ++k) dp[0][k] = -1; for (int i = 1; i <= n; ++i) { if (ant[i] < dp[i-1][0]) dp[i][0] = dp[i-1][0]; else dp[i][0] = ant[i]; for (int k = 1; k < MAXK; ++k) if (dp[i][k-1] != -1) dp[i][k] = dp[dp[i][k-1]][k-1]; else dp[i][k] = -1; } int q; cin >> q; for (int i = 0; i < q; ++i) { int l, r; cin >> l >> r; int ans = 0; for (int k = MAXK - 1; k >= 0; --k) if (dp[r][k] >= l-1) { r = dp[r][k]; ans += 1 << k; } cout << ans << "\n"; } }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for (int i = 1; i < xs.size(); ++i)
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...