// Author: caption_mingle
#include "bits/stdc++.h"
#include "bubblesort2.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
struct SEGTREE {
	vector<int> st, lazy;
	int n;
	SEGTREE(int n) : n(n) {
		st.resize(n * 4 + 4, 0);
		lazy.resize(n * 4 + 4, 0);
	}
	void push(int i) {
		if(lazy[i]) {
			int x = lazy[i];
			lazy[i] = 0;
			lazy[i * 2] += x;
			lazy[i * 2 + 1] += x;
			st[i * 2] += x;
			st[i * 2 + 1] += x;
		}
	}
	void update(int i, int l, int r, int u, int v, int x) {
		if(l > v or r < u) return;
		if(u <= l and r <= v) {
			st[i] += x;
			lazy[i] += x;
			return;
		}
		push(i);
		int m = (l + r) >> 1;
		update(i * 2, l, m, u, v, x);
		update(i * 2 + 1, m + 1, r, u, v, x);
		st[i] = max(st[i * 2], st[i * 2 + 1]);
	}
	int get(int i, int l, int r, int u, int v) {
		if(l > v or r < u) return 0;
		if(u <= l and r <= v) return st[i];
		push(i);
		int m = (l + r) >> 1;
		return max(get(i * 2, l, m, u, v), get(i * 2 + 1, m + 1, r, u, v));
	}
	void update(int l, int r, int x) {
		if(l > r) return;
		update(1, 0, n, l, r, x);
	}
	int get(int l, int r) {
		if(l > r) return 0;
		return get(1, 0, n, l, r);
	}
};
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
	int n = sz(A), q = sz(X);
	vector<int> ans;
	vector<pair<int, int>> val;
	for(int i = 0; i < n; i++) val.pb({A[i], i});
	for(int i = 0; i < q; i++) val.pb({V[i], X[i]});
	sort(all(val));
	val.erase(unique(all(val)), val.end());
	int m = sz(val);
	SEGTREE st(m);
	for(int i = 0; i < n; i++) {
		A[i] = upper_bound(all(val), make_pair(A[i], i)) - val.begin();
		st.update(A[i], A[i], i);
		st.update(A[i] + 1, m, -1);
	}
	for(int i = 0; i < n; i++) {
		V[i] = upper_bound(all(val), make_pair(V[i], X[i])) - val.begin();
	}
	for(int i = 0; i < q; i++) {
		st.update(A[X[i]], A[X[i]], -X[i]);
		st.update(A[X[i]] + 1, m, 1);
		A[X[i]] = V[i];
		st.update(A[X[i]], A[X[i]], X[i]);
		st.update(A[X[i]] + 1, m, -1);
		ans.pb(st.st[1]);
	}
	return ans;
}
// int main() {
// 	int n, q; cin >> n >> q;
// 	vector<int> A, X, V;
// 	for(int i = 1; i <= n; i++) {
// 		int x; cin >> x;
// 		A.pb(x);
// 	}
// 	for(int i = 1; i <= q; i++) {
// 		int x, v; cin >> x >> v;
// 		X.pb(x);
// 		V.pb(v);
// 	}
// 	vector<int> ans = countScans(A, X, V);
// 	for(int x : ans) {
// 		cout << x << ln;
// 	}
// }
| # | 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... |