Submission #1013712

#TimeUsernameProblemLanguageResultExecution timeMemory
1013712vjudge1Bubble Sort 2 (JOI18_bubblesort2)C++17
0 / 100
5317 ms64092 KiB
#include "bubblesort2.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector <ll>; using vi = vector <int>; // using ii = pair <ll, ll>; // using vii = vector <ii>; const ll MAXN = 5E5+16, INF = ll(1E18)+16; priority_queue <ll> pq[2*MAXN]; struct SegTree { function <ll(ll, ll)> op; ll idem; vll tree; ll n; SegTree (ll n, function <ll(ll, ll)> op, ll idem): op(op), idem(idem), tree(2*n, idem), n(n) {} void update (ll id, ll val) { tree[id] = val; } void update (ll ql, ll qr, ll val) { for (ll i = ql; i <= qr; i++) tree[i] = op(tree[i], val); } ll query (ll ql, ll qr) { ll ans = idem; for (ll i = ql; i <= qr; i++) ans = op(ans, tree[i]); return ans; } }; vi countScans (vi a, vi wh, vi val) { vll ve(a.begin(), a.end()); ll n = a.size(); ll Q = wh.size(); {vll th = ve; for (int i : val) th.push_back(i); sort(th.begin(), th.end()); th.resize(unique(th.begin(), th.end()) - th.begin()); for (ll &i : ve) i = lower_bound(th.begin(), th.end(), i) - th.begin() ; for (int &i : val) i = lower_bound(th.begin(), th.end(), i) - th.begin() ;} SegTree stFreq(1E6+16, [&](ll a, ll b){return a+b;}, 0); SegTree stAns(1E6+16, [&](ll a, ll b){return max(a,b);}, -INF); vi ans; for (ll i = 0; i < n; i++) { pq[ve[i]].push(i); stFreq.update(ve[i], 1); } auto redo = [&](ll i) { while (pq[i].size() && ve[pq[i].top()] != i) pq[i].pop(); stAns.update(i, -INF); if (!pq[i].size()) return; stAns.update(i, pq[i].top()+1 - stFreq.query(0, i)); }; for (ll i = 0; i < n+wh.size(); i++) redo(i); for (ll q = 0; q < Q; q++) { ll val1 = ve[wh[q]], val2 = val[q]; stFreq.update(ve[wh[q]], ve[wh[q]], -1); ve[wh[q]] = val[q]; stFreq.update(ve[wh[q]], ve[wh[q]], +1); pq[val[q]].push(wh[q]); stAns.update(0, val1, -1); stAns.update(0, val2, +1); redo(val1); redo(val2); ans.push_back(stAns.query(0, 1E6+4)); } return ans; }

Compilation message (stderr)

bubblesort2.cpp: In function 'vi countScans(vi, vi, vi)':
bubblesort2.cpp:59:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'long long unsigned int' [-Wsign-compare]
   59 |     for (ll i = 0; i < n+wh.size(); i++) redo(i);
      |                    ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...