莫队蒟蒻求调 莫名WA on #3
查看原帖
莫队蒟蒻求调 莫名WA on #3
247842
zhenji_190127楼主2021/6/21 09:50

改了半天了

孩子要改哭了

#include<bits/stdc++.h>
using namespace std;
int n,m;
int col[100010];
struct Q
{
	int l,r;
	int his;
	int num;
}q[100010]; 
map<int ,int >book;
struct C
{
	int pos;
	int val;//修改值同样需要离散化记得和考虑 
}c[100010];
int size;
bool cmp(Q a,Q b)
{
	if(a.l/size==b.l/size)
	{
		if(a.r/size==b.r/size)
			return a.his<b.his; 
		else
			return 	a.r<b.r;
	}
	return a.l<b.l;
}
int count1[100010];
int count2[100010];
void add(int COL)
{ 
	count2[count1[COL]]--;
	count1[COL]++;
	count2[count1[COL]]++;
}
void remove(int COL)
{
	count2[count1[COL]]--;
	count1[COL]--;
	count2[count1[COL]]++;	
}
void update(int h,int l,int r)
{
	if(c[h].pos<=r&&l<=c[h].pos)
	{
	add(c[h].val);
	remove(col[c[h].pos]);		
	}
	swap(col[c[h].pos],c[h].val);
}
int mex()//暴力求解mex
{
	for(int i=1;;i++)
		if(count2[i]==0)return i;
}
int ans[100010];
int main()
{
	scanf("%d%d",&n,&m);
	int tot=0;
	for(int i=1;i<=n;i++)
	{
		int in;
		scanf("%d",&in);
		if(book[in]==0)
		book[in]=++tot;
		col[i]=book[in];
	}
	//输入询问
	size=ceil(pow(n,2.0/3));
	int his_cnt=0;
	int tot_cnt=0;
	for(int i=1;i<=m;i++)
	{
		int option;
		scanf("%d",&option);
		if(option==1)
		{
			tot_cnt++;
			int l,r;
			scanf("%d%d",&l,&r);
			q[tot_cnt].l=l;
			q[tot_cnt].r=r;
			q[tot_cnt].his=his_cnt;
			q[tot_cnt].num=tot_cnt;
		}
		if(option==2)
		{
			his_cnt++;
			int pos;
			int val;
			scanf("%d%d",&pos,&val);
			c[his_cnt].pos=pos;
			if(book[val]==0)
				book[val]=++tot;
			c[his_cnt].val=book[val];
		}
	}
	sort(q+1,q+tot_cnt+1,cmp);
	int l=0,r=0,h=0;
	for(int i=1;i<=tot_cnt;i++)
	{
		while(r<q[i].r)add(col[++r]);
		while(r>q[i].r)remove(col[r--]);
		while(l>q[i].l)add(col[--l]);
		while(l<q[i].l)remove(col[l++]);
		while(h<q[i].his)update(++h,l,r);
		while(h>q[i].his)update(h--,l,r);
		ans[q[i].num]=mex();
	}
	for(int i=1;i<=tot_cnt;i++)
		printf("%d\n",ans[i]);
	return 0;
}

谢谢谢谢!!!!

2021/6/21 09:50
加载中...