Question is intended: to give you a n, and n random permutation of 1-n, which is selected from a sequence period, to make the sequence order is 1-m, m is the Beautiful Numbers, if 1-n is Beautiful Numbers the output 1,
Otherwise, output 0;
Thinking: will randomly arranged into an array of positions p, for example, a position corresponding to 3, p [1] = 3,2 corresponding to position 4, the p [2] = 4;
Taken individually sequences array p, l always marked with a sequence start position, end position marker sequence R & lt always determines whether the r-l + 1 to the current i.
#include<bits/stdc++.h> #define N 2e5+10 using namespace std; int main(){ int t,i,n,p[int(N)],a,l,r; while(~scanf("%d",&t)){ while(t--){ memset(p,0,sizeof(p)); scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a); p[a]=i; } l=r=p[1]; printf("1"); for(i=2;i<=n;i++){ l=min(l,p[i]); r=max(r,p[i]); if(r-l+1==i) printf("1"); else printf("0"); } printf("\n"); } } }