题意:给定一个排列,每次可以选择相邻的三个数,将最大和最小的数删除
问对于中每个,可不可能是最后被保留下来的那个数?
首先我们要想明白一件事,当一个数组中大于和小于的数量相等时,一定可以被保留下来
而对于在排列中任意一个数,比他大的数和比他小的数的数量之差等于
也就是说如果我们可以把多出的这些部分按题目意思消掉,就是可保留的
我们把大于的数字记作1,小于的数字记成0
按题目意思,连续三个1或连续三个0可以消掉两个,使得多出的部分减2
而对于不连续的
假设我们多出的是大于的数,用1表示
11011可以先变成111进而变成1,贡献相当于111
所以我们可以巧妙的维护一个tmp,遇到想要消掉的数++,不想消掉的数--
满三减二
而对于本身,是不能被跨越的,所以经过时tmp要置0
代码如下:
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fer(i,a,b) for(int i=a;i<=b;++i)
#define der(i,a,b) for(int i=a;i>=b;--i)
#define all(x) (x).begin(),(x).end()
#define pll pair<int,int>
#define et cout<<'\n'
#define xx first
#define yy second
using namespace std;
template <typename _Tp>void input(_Tp &x){
char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
if(f)x=-x;
}
template <typename _Tp,typename... Args>void input(_Tp &t,Args &...args){input(t);input(args...);}
const int N=1e6+10;
int a[N];
int n;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin>>T;
while(T--){
cin>>n;
fer(i,1,n) cin>>a[i];
function<bool(int)> check=[](int tar){
bool fl=a[tar]<(n+1)/2;
int k=a[tar]-1;
int k2=n-a[tar];
k=abs(k-k2);
int tmp=0;
fer(i,1,n){
if(i==tar){
tmp=0;
continue;
}
if((a[i]<a[tar])!=fl){
tmp++;
if(tmp==3){
tmp=1;
k-=2;
}
}
else{
tmp=max(tmp-1,0ll);
}
}
return k<=0;
};
fer(i,1,n){
cout<<check(i);
}
cout<<endl;
}
}