Submission #1112632

#TimeUsernameProblemLanguageResultExecution timeMemory
1112632_callmelucianSum Zero (RMI20_sumzero)C++14
61 / 100
196 ms26552 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tpl; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const int mn = 4e5 + 5; int nxt[mn], ans[mn], qryL[mn], qryR[mn], calc[mn][2], last[mn]; vector<ll> cmp; ll pre[mn]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; last[0] = 0, nxt[0] = -1; cmp.push_back(0); for (int i = 1; i <= n; i++) { ll a; cin >> a; pre[i] = pre[i - 1] + a, cmp.push_back(pre[i]); } sort(all(cmp)), filter(cmp); for (int i = 0; i < cmp.size(); i++) last[i] = -1; int nearest = -1; for (int i = 0; i <= n; i++) { // if (last.count(pre)) // nearest = max(nearest, last[pre]); // last[pre] = i, nxt[i] = nearest; int p = lower_bound(all(cmp), pre[i]) - cmp.begin(); nearest = max(nearest, last[p]), last[p] = i, nxt[i] = nearest; } int q; cin >> q; for (int i = 0; i < q; i++) { cin >> qryL[i] >> qryR[i]; qryL[i]--; } for (int s = 18; s >= 0; s--) { for (int i = 0; i <= n; i++) calc[i][0] = nxt[i]; for (int j = 1; j <= s; j++) { int t = j & 1; for (int i = 0; i <= n; i++) calc[i][t] = (calc[i][t ^ 1] == -1 ? -1 : calc[calc[i][t ^ 1]][t ^ 1]); } for (int i = 0; i < q; i++) if (qryL[i] <= calc[qryR[i]][s & 1]) ans[i] |= (1 << s), qryR[i] = calc[qryR[i]][s & 1]; } for (int i = 0; i < q; i++) cout << ans[i] << "\n"; return 0; }

Compilation message (stderr)

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