#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
const int N = 1e6 + 5;
int n, q;
vector<pii> vec;
int st[4 * N];
int delta[4 * N];
void update(int id, int l, int r, int u, int v, int x) {
if (u > r || v < l) return;
if (u <= l && r <= v) {
st[id] += x;
delta[id] += x;
return;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, u, v, x);
update(id * 2 + 1, mid + 1, r, u, v, x);
st[id] = delta[id] + max(st[id * 2], st[id * 2 + 1]);
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
for (int i = 0; i < A.size(); i++) {
vec.pb({A[i], i});
}
for (int i = 0; i < X.size(); i++) {
vec.pb({V[i], X[i]});
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (int i = 0; i < A.size(); i++) {
A[i] = upper_bound(vec.begin(), vec.end(), make_pair(A[i], i)) - vec.begin();
update(1, 1, vec.size(), A[i], A[i], i);
update(1, 1, vec.size(), A[i] + 1, vec.size(), -1);
}
vector<int> res;
for (int i = 0; i < X.size(); i++) {
update(1, 1, vec.size(), A[X[i]], A[X[i]], - X[i]);
update(1, 1, vec.size(), A[X[i]] + 1, vec.size(), 1);
V[i] = upper_bound(vec.begin(), vec.end(), make_pair(V[i], X[i])) - vec.begin();
A[X[i]] = V[i];
update(1, 1, vec.size(), A[X[i]], A[X[i]], X[i]);
update(1, 1, vec.size(), A[X[i]] + 1, vec.size(), -1);
res.pb(st[1]);
}
return res;
}
// signed main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// vector<int> A;
// vector<int> X;
// vector<int> V;
// cin >> n >> q;
// for (int i = 1; i <= n; i++) {
// int x;
// cin >> x;
// A.pb(x);
// }
// for (int i = 1; i <= q; i++) {
// int x;
// cin >> x;
// X.pb(x);
// }
// for (int i = 1; i <= q; i++) {
// int x;
// cin >> x;
// V.pb(x);
// }
// vector<int> res = countScans(A, X, V);
// for (int i : res) {
// cout << i << ' ';
// }
// }
# | 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... |