#include <bits/stdc++.h>
// #include "bubblesort2.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 5e5 + 69;
const int INF = 1e9 + 69;
int di(int x, int y){
return x / y + (x % y > 0);
}
struct SegmentTree{
int n;
vector<int> a, lazy;
SegmentTree(int _n){
n = _n;
a.resize(n * 4 + 4); lazy.resize(n * 4 + 4);
}
void update_node(int i, int v){
a[i] += v;
lazy[i] += v;
}
void down(int id){
update_node(id * 2, lazy[id]); update_node(id * 2 + 1, lazy[id]);
lazy[id] = 0;
}
void update(int u, int v, int val){if (u <= v) update(u, v, val, 0, n-1, 1);}
void update(int u, int v, int val, int l, int r, int id){
if (u <= l && r <= v){
update_node(id, val);
return;
}
if (lazy[id]) down(id);
int mid = (l + r) >> 1;
if (u <= mid) update(u, v, val, l, mid, id * 2);
if (v > mid) update(u, v, val, mid + 1, r, id * 2 + 1);
a[id] = max(a[id * 2], a[id * 2 + 1]);
}
int get(){return a[1];}
};
set<int> st[N * 2];
vector<int> countScans(vector<int> a,vector<int> X,vector<int> V){
int n = a.size(), q = X.size();
vector<int> b = a;
for(int i: V) b.push_back(i);
remove_dup(b);
for(int &i: a) i = lower_bound(ALL(b), i) - b.begin();
for(int &i: V) i = lower_bound(ALL(b), i) - b.begin();
for(int i = 0; i < n; ++i){
st[a[i]].insert(i);
}
int m = b.size();
SegmentTree segg(m);
for(int i = 0; i < m; ++i){
st[i].insert(-INF);
segg.update(i, i, *st[i].rbegin());
segg.update(i, m - 1, -st[i].size() + 1);
}
vector<int> answer(q);
for(int cur_query = 0; cur_query < q; ++cur_query){
int i = X[cur_query], j = V[cur_query];
segg.update(a[i], m - 1, 1);
segg.update(a[i], a[i], -*st[a[i]].rbegin());
st[a[i]].erase(i);
segg.update(a[i], a[i], *st[a[i]].rbegin());
a[i] = j;
segg.update(a[i], m - 1, -1);
segg.update(a[i], a[i], -*st[a[i]].rbegin());
st[a[i]].insert(i);
segg.update(a[i], a[i], *st[a[i]].rbegin());
answer[cur_query] = segg.get() + 1;
}
return answer;
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
vector<int> a(n);
for(int i = 0; i<n; ++i) cin >> a[i];
vector<int> x(q), v(q);
for(int i = 0; i<q; ++i) cin >> x[i] >> v[i];
printArr(countScans(a, x, v));
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccD2wEHf.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cclkVaIe.o:bubblesort2.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status