Submission #942739

#TimeUsernameProblemLanguageResultExecution timeMemory
942739ShadowSharkSum Zero (RMI20_sumzero)C++17
61 / 100
644 ms29976 KiB
#include <bits/stdc++.h> using namespace std; const int maxN = 4e5 + 9; int a[maxN], jump[9][maxN]; map<long long, int> appear; vector<pair<int, int>> segment; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; appear[0] = 0; long long sum = 0; for (int i = 1; i <= n; i++) { sum = sum + a[i]; if (appear[sum] != 0) segment.push_back({i, appear[sum] + 1}); else if (sum == 0) segment.push_back({i, 1}); appear[sum] = i; } sort(segment.begin(), segment.end()); int curr = 0; jump[0][n + 1] = n + 1; for (int i = 0; i <= n; i++) { while (curr < segment.size() && i >= segment[curr].second) curr++; if (curr == segment.size()) jump[0][i] = n + 1; else jump[0][i] = segment[curr].first; } for (int i = 1; i <= 8; i++) for (int j = 0; j <= n + 1; j++) jump[i][j] = jump[i - 1][jump[i - 1][j]]; int q; cin >> q; while (q--) { int l, r; cin >> l >> r; int ans = 0; l--; for (int i = 8; i >= 0; i--) while (jump[i][l] <= r) { l = jump[i][l]; ans += 1 << i; } cout << ans << '\n'; } return 0; }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while (curr < segment.size() && i >= segment[curr].second) curr++;
      |                ~~~~~^~~~~~~~~~~~~~~~
sumzero.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if (curr == segment.size()) jump[0][i] = n + 1;
      |             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...