#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
// set
typedef tree<
pi,
null_type,
less<pi>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int MAXN = 5e5 + 100;
const int INF = 1e9;
struct LSegTr {
int tr[4 * MAXN], lz[4 * MAXN];
void push(int i, int l, int r) {
tr[i] += lz[i];
if (l != r) {
lz[i * 2] += lz[i];
lz[i * 2 + 1] += lz[i];
}
lz[i] = 0;
}
int q(int i, int l, int r, int s, int e) {
if (e < l || r < s) {
return 0;
}
push(i, l, r);
if (s <= l && r <= e) {
return tr[i];
}
int mid = (l + r) / 2;
return max(q(i * 2, l, mid, s, e), q(i * 2 + 1, mid + 1, r, s, e));
}
void u(int i, int l, int r, int s, int e, int d) {
push(i, l, r); // pushed early to use in recalculation of parent
if (e < l || r < s) {
return;
}
if (s <= l && r <= e) {
lz[i] += d;
push(i, l, r);
return;
}
int mid = (l + r) / 2;
u(i * 2, l, mid, s, e, d);
u(i * 2 + 1, mid + 1, r, s, e, d);
tr[i] = max(tr[i * 2], tr[i * 2 + 1]);
}
void set(int i, int l, int r, int x, int v) {
push(i, l, r);
if (l == r) {
tr[i] = v;
return;
}
int mid = (l + r) / 2;
if (x <= mid) {
set(i * 2, l, mid, x, v);
} else {
set(i * 2 + 1, mid + 1, r, x, v);
}
tr[i] = max(tr[i * 2], tr[i * 2 + 1]);
}
void b(int i, int l, int r, vi &init) {
lz[i] = 0;
if (l == r) {
tr[i] = init[l];
return;
}
int mid = (l + r) / 2;
b(i * 2, l, mid, init);
b(i * 2 + 1, mid + 1, r, init);
}
} lSegTr;
int N, Q;
ordered_set vals;
vi countScans(vi A, vi X, vi V) {
vector<pi> allVal;
vi a(A.begin(), A.end());
N = a.size();
Q = X.size();
for (int i = 0; i < N; i++) {
allVal.pb({a[i], i});
}
for (int i = 0; i < Q; i++) {
allVal.pb({V[i], X[i]});
}
sort(allVal.begin(), allVal.end());
allVal.erase(unique(allVal.begin(), allVal.end()), allVal.end());
for (int i = 0; i < N; i++) {
vals.insert({a[i], i});
}
int M = allVal.size();
vi init(M);
for (int cP = 0; cP < N; cP++) {
pi cVal = {a[cP], cP};
int gP = vals.order_of_key(cVal);
int index = lower_bound(allVal.begin(), allVal.end(), cVal) - allVal.begin();
init[index] = cP - gP;
}
lSegTr.b(1, 0, M - 1, init);
vi ans(Q);
for (int cQ = 0; cQ < Q; cQ++) {
int cP = X[cQ];
pi oV = {a[cP], cP};
pi nV = {V[cQ], cP};
a[cP] = V[cQ];
vals.erase(oV);
vals.insert(nV);
int oIndex = upper_bound(allVal.begin(), allVal.end(), oV) - allVal.begin();
int nIndex = upper_bound(allVal.begin(), allVal.end(), nV) - allVal.begin();
if (oIndex < M) lSegTr.u(1, 0, M - 1, oIndex, M - 1, +1);
if (nIndex < M) lSegTr.u(1, 0, M - 1, nIndex, M - 1, -1);
lSegTr.set(1, 0, M - 1, oIndex, -INF);
int gP = vals.order_of_key(nV);
lSegTr.set(1, 0, M - 1, nIndex, cP - gP);
ans[cQ] = lSegTr.q(1, 0, M - 1, 0, M - 1);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
3316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |