Codeforces #940F: Machine Learning 题解

可以考虑带修改的莫队

统计答案可以暴力,因为可以证明mex的这个答案是根号级别的

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=3048;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n,q;
int a[300048];
vector na[300048];

struct UPDATE
{
	int ind;
	int pos;int x,nx;
}upd[300048];int utot;

struct QUERY
{
	int ind,left,right,num;
	inline bool operator < (QUERY x)
	{
		if (left/magic!=x.left/magic) return left/magic=0;i--)
			if ((res|(1<que[i].right)
		{
			doit_minus(cur_right);
			cnt[na[cur_right].back()]--;
			doit_plus(cur_right);
			cur_right--;
		}
		while (cur_leftque[i].left)
		{
			cur_left--;
			doit_minus(cur_left);
			cnt[na[cur_left].back()]++;
			doit_plus(cur_left);
		}
		while (cur_updque[i].num)
		{
			if (que[i].left<=upd[cur_upd].pos && upd[cur_upd].pos<=que[i].right)
			{
				doit_minus(upd[cur_upd].pos);
				cnt[na[upd[cur_upd].pos].back()]--;
				doit_plus(upd[cur_upd].pos);
				na[upd[cur_upd].pos].pop_back();
				doit_minus(upd[cur_upd].pos);
				cnt[na[upd[cur_upd].pos].back()]++;
				doit_plus(upd[cur_upd].pos);
			}
			else
				na[upd[cur_upd].pos].pop_back();
			cur_upd--;
		}
		ans[que[i].ind]=calc();
	}
	for (i=1;i<=q;i++)
		if (ans[i]) printf("%d\n",ans[i]);
	return 0;
}

你可能感兴趣的:(莫队)