#include <bits/stdc++.h>
/// #include "bubblesort2.h"
#define INF 0x3f3f3f3f
using namespace std;
struct ST {
int n;
vector<int> t, lazy;
ST(int N) : n(N) {
int dim = 1;
while (dim < n) {
dim *= 2;
}
dim *= 2;
t.resize(dim, -INF);
lazy.resize(dim);
}
void updateNode(int x, int v) {
t[x] += v;
lazy[x] += v;
}
void push(int x) {
if (lazy[x] == 0) {
return;
}
for (int i = 0; i < 2; ++i) {
updateNode(x * 2 + i, lazy[x]);
}
lazy[x] = 0;
}
void update(int x, int lx, int rx, int st, int dr, int v) {
if (st <= lx && rx <= dr) {
updateNode(x, v);
return;
}
push(x);
int mid = (lx + rx) / 2;
if (st <= mid) {
update(x * 2, lx, mid, st, dr, v);
}
if (mid < dr) {
update(x * 2 + 1, mid + 1, rx, st, dr, v);
}
t[x] = max(t[x * 2], t[x * 2 + 1]);
}
void update(int st, int dr, int v) {
if (dr < st) {
return;
}
update(1, 0, n - 1, st, dr, v);
}
int getMax() {
return t[1];
}
};
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v) {
int n = a.size(), q = x.size();
vector<pair<int, int>> pairs;
pairs.reserve(n + q);
for (int i = 0; i < n; ++i) {
pairs.emplace_back(a[i], i);
}
for (int i = 0; i < q; ++i) {
pairs.emplace_back(v[i], x[i]);
}
sort(pairs.begin(), pairs.end());
map<pair<int, int>, int> order;
order[pairs[0]] = 1;
int N = 0;
for (int i = 1; i < (int)pairs.size(); ++i) {
if (pairs[i] != pairs[i - 1]) {
N += 1;
}
order[pairs[i]] = N;
}
N += 1;
ST t(N);
auto update = [&](const int &index, const int &pos, const int &sgn) -> void {
t.update(index, index, sgn * INF);
t.update(index, index, sgn * pos);
t.update(index + 1, N - 1, -sgn);
};
for (int i = 0; i < n; ++i) {
update(order[{a[i], i}], i, 1);
}
vector<int> sol(q);
for (int i = 0; i < q; ++i) {
update(order[{a[x[i]], x[i]}], x[i], -1);
a[x[i]] = v[i];
update(order[{a[x[i]], x[i]}], x[i], 1);
sol[i] = t.getMax();
}
return sol;
}
void testCase() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
vector<int> x(q), v(q);
for (int i = 0; i < q; ++i) {
cin >> x[i] >> v[i];
}
vector<int> sol = countScans(a, x, v);
for (int s : sol) {
cout << s << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
Compilation message
/usr/bin/ld: /tmp/cc5QUnSo.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccT4XRAr.o:bubblesort2.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status