CF940F 带修莫队

#include <bits/stdc++.h>
using namespace  std;
#define  int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb  push_back
#define inf 1<<62
#define endl "\n"
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define de_bug(x) cerr << #x << "=" << x << endl
#define all(a) a.begin(),a.end()
#define IOS   std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define  fer(i,a,b)  for(int i=a;i<=b;i++)
#define  der(i,a,b)  for(int i=a;i>=b;i--)
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
int n, m , k;

int len;
int a[N];
int ans[N], b[N];
int cnt[N];
int b1[N];
//unordered_map<int,int>cnt;
int f[N];
struct node {
	int id, l, r, t;
	bool operator <(const node &a)const {
		if(b1[l]^b1[a.l]) return b1[l] < b1[a.l];
		if(b1[r]^b1[a.r]) return b1[r] < b1[a.r];
		return b1[t] < b1[a.t];
	}
} q[N];
pii c[N];

void add(int x) {
	f[cnt[x]]--;
	++cnt[x];
	f[cnt[x]]++;
}
void del(int x) {
	f[cnt[x]]--;
	--cnt[x];
	f[cnt[x]]++;
}

int q1, q2;
int cnt1;
void solve() {
	cin >> n >> m;
	len = pow(n, 2.0 / 3.0);
	for(int i = 1; i <= n; i++) b1[i] = (i - 1) / len + 1;
	for(int i = 1; i <= n; i++)cin >> a[i],b[++cnt1]=a[i];
	for(int i = 1; i <= m; i++) {
		int  op;
		int a, bb;
		cin >> op >> a >> bb;
		if(op == 1) q1++ , q[q1] = {q1, a, bb, q2};
		else  c[++q2] = {a, bb},b[++cnt1]=bb;
	}
	sort(q + 1, q + q1 + 1);
	sort(b+1,b+cnt1+1);
	int cnt2=unique(b+1,b+cnt1+1)-b-1;
	//de_bug(cnt2);
	fer(i,1,n) {
		a[i]=lower_bound(b+1,b+cnt2+1,a[i])-b-1;
	}
	fer(i,1,q2) {
		c[i].se=lower_bound(b+1,b+cnt2+1,c[i].se)-b-1;
	}
	for(int i = 0, j = 1, t = 0, k = 1; k <= q1; k++) {
		int id = q[k].id;
		int l = q[k].l;
		int r = q[k].r;
		int tt = q[k].t;
		while(i < r) add(a[++i]);
		while(i > r) del(a[i--]);
		while(j < l) del(a[j++]);
		while(j > l) add(a[--j]);
		while(t < tt) {
			t++;
			if(c[t].fi >= j && c[t].fi <= i) {
				del(a[c[t].fi]);
				add(c[t].se);
			}
			swap(a[c[t].fi], c[t].se);
		}
		while(t > tt) {
			if(c[t].fi >= j && c[t].fi <= i) {
				del(a[c[t].fi]);
				add(c[t].se);
			}
			swap(a[c[t].fi], c[t].se);
			t--;
		}
		int res=1;
		//de_bug(bel[0]);
		while(f[res])res++;
		ans[id] = res;
	}
//	cout<<q1<<endl;
	for(int i = 1; i <= q1; i++) {
		cout << ans[i] << endl;
		//cout << ans[i] << " \n"[i == q1];
	}
}
signed main() {
	IOS;
	int _ = 1;
	//cin>>_;
	while( _-- )
		solve();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值