题解:P17204 「DLESS-6」XOR and MEX
nyt_nyt2012 · · 题解
先说结论:求
怎么证?一发过了,得证。
证明:首先,设原序列的
那怎么找到 bool 数组,每次将下标为 bitset 即可。
如果我们懒,还能这样做:由于 bitset 只用开到 bitset 有一个冷门函数 _Find_first(),可以返回第一个值为 _Find_first() 即可。实现非常简单,时间复杂度为 fread 快读,所以空间消耗会更大,但可过。
:::success[代码]
#include<bits/stdc++.h>
using namespace std;
uint8_t buf[1<<20],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin)),*p1++)
inline unsigned int read(){
unsigned int x=0;
char ch=gc();
while(!isdigit(ch))ch=gc();
while(isdigit(ch))x=x*10+(ch&15),ch=gc();
return x;
}
bitset<1000000>b;
bitset<1000000>c;
int main(){
int t=read();
while(t--){
b.reset();
int n=read();
for(int i=1;i<=n;i++){
int a=read();
if(a<1000000)b[a]=1;
}
c=~b;
cout<<c._Find_first()<<"\n";
}
return 0;
}
:::