# JZOJ5710. 【北大夏令营2018模拟5.13】Mex

5 4 0
2 1 0 2 1
3 3
2 3
2 4
1 2

1
2
3
0

## code

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 200003
#define M 1000000003
#define db double
#define P putchar
#define G getchar
#define inf 998244353
#define pi 3.1415926535897932384626433832795
using namespace std;
char ch;
{
n=0;
ch=G();
while((ch<'0' || ch>'9') && ch!='-')ch=G();
ll w=1;
if(ch=='-')w=-1,ch=G();
while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
n*=w;
}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll abs(ll x){return x<0?-x:x;}
ll sqr(ll x){return x*x;}
void write(ll x){if(x>9) write(x/10);P(x%10+'0');}

struct node
{
int l,r,s;
}tr[N*40];

int n,m,T,tot,t,ans,opl,opr,pos;

void ins(int x,int y,int l,int r)
{
tr[x]=tr[y];
if(l==r)
{
tr[x].s=pos;
return;
}
int m=(l+r)>>1;
if(t<=m)ins(tr[x].l=++tot,tr[y].l,l,m);
else ins(tr[x].r=++tot,tr[y].r,m+1,r);
tr[x].s=min(tr[tr[x].l].s,tr[tr[x].r].s);
}

int find(int x,int l,int r)
{
if(l==r)return l;
int m=(l+r)>>1;
if(tr[tr[x].l].s<opl)return find(tr[x].l,l,m);
else return find(tr[x].r,m+1,r);
}

int main()
{
freopen("mex.in","r",stdin);
freopen("mex.out","w",stdout);

for(register int i=1;i<=n;i++)
{
ins(i,i-1,1,M);
}

ans=0;
for(register int i=1;i<=m;i++)
{
if(T)opl^=ans,opr^=ans;
ans=find(opr,1,M)-1;
write(ans),P('\n');
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120