# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
204724 | 2020-02-26T18:46:56 Z | Kastanda | Bubble Sort 2 (JOI18_bubblesort2) | C++11 | 0 ms | 0 KB |
// In The Name Of The Queen #include<bits/stdc++.h> #include "bubblesort2.h" using namespace std; const int N = 500005, MXS = N * 2 * 4; int n, q, MX[MXS], LZ[MXS]; vector < pair < int , int > > U; void Add(int le, int ri, int val, int id = 1, int l = 0, int r = (int)U.size()) { if (ri <= l || r <= le) return ; if (le <= l && r <= ri) { MX[id] += val; LZ[id] += val; return ; } Add(le, ri, val, lc, l, md); Add(le, ri, val, rc, md, r); MX[id] = max(MX[lc], MX[rc]) + LZ[id]; } vector < int > countScans(vector < int > A, vector < int > X, vector < int > V) { n = (int)A.size(); q = (int)X.size(); for (int i = 0; i < n; i ++) U.push_back({A[i], i}); for (int i = 0; i < q; i ++) U.push_back({V[i], X[i]}); sort(U.begin(), U.end()); U.resize(unique(U.begin(), U.end()) - U.begin()); auto GetId = [&] (pair < int , int > val) { return (int)(lower_bound(U.begin(), U.end(), val) - U.begin()); }; auto Apply = [&] (int i, int val) { int p = GetId({A[i], i}); Add(p, p + 1, i * val); int l = GetId({A[i], -1}); Add(l, (int)U.size(), val); }; for (int i = 0; i < n; i ++) Apply(i, 1); vector < int > R; for (int i = 0; i < q; i ++) { Apply(X[i], -1); A[X[i]] = V[i]; Apply(X[i], 1); R.push_back(MX[1]); } return (R); }