This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// http://s3-ap-northeast-1.amazonaws.com/data.cms.ioi-jp.org/open-2018/2018-open-bubblesort2-sol-en.pdf
#include<iostream>
#include<algorithm>
#include<vector>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define ff first
#define ss second
const int N = 5e5 + 5, SZ = 1 << 21, inf = 1e9 + 7;
int n, q, nq;
int seg[SZ], laz[SZ];
void upd(int u, int l, int r, int a, int b, int v) {
if (a <= l && r <= b) {
seg[u] += v;
laz[u] += v;
return;
}
int m = (l + r) >> 1, u1 = u << 1, u2 = u1 | 1;
if (laz[u]) {
seg[u1] += laz[u];
seg[u2] += laz[u];
laz[u1] += laz[u];
laz[u2] += laz[u];
laz[u] = 0;
}
if (a <= m) upd(u1, l, m, a, b, v);
if (m < b) upd(u2, m + 1, r, a, b, v);
seg[u] = max(seg[u1], seg[u2]);
}
void compress(vector<int> &a, const vector<int> &x, vector<int> &v) {
vector<pii> b;
for (int i = 0; i < n; ++i) b.emplace_back(a[i], i);
for (int i = 0; i < q; ++i) b.emplace_back(v[i], x[i]);
sort(all(b));
b.resize(unique(all(b)) - b.begin());
for (int i = 0; i < n; ++i) a[i] = lower_bound(all(b), pii(a[i], i)) - b.begin();
for (int i = 0; i < q; ++i) v[i] = lower_bound(all(b), pii(v[i], x[i])) - b.begin();
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
n = a.size(), q = x.size(), nq = n + q - 1;
compress(a, x, v);
upd(1, 0, nq, 0, nq, -inf);
for (int i = 0; i < n; ++i) {
upd(1, 0, nq, a[i], a[i], inf + i);
upd(1, 0, nq, a[i] + 1, nq, -1);
}
vector<int> ans;
for (int i = 0, j; i < q; ++i) {
j = x[i];
upd(1, 0, nq, a[j], a[j], -inf - j);
upd(1, 0, nq, a[j] + 1, nq, 1);
a[j] = v[i];
upd(1, 0, nq, a[j], a[j], inf + j);
upd(1, 0, nq, a[j] + 1, nq, -1);
ans.push_back(seg[1]);
}
return ans;
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |