这道题我赛时没看懂,没理解上,赛后补题的时候看了dalao的代码懂得。这里n^2logn会T,那么我们想办法去掉logn,这里需要我们理解lis的本质,即去掉序列中的一个数,那么以i结尾的序列的LIS的长度要吗不变,要么-1,
#include <bits/stdc++.h>
#define maxs 202020
#define mme(I,j) memset(I,j,sizeof(I))
using namespace std;
const int inf = ( ~(1<<31) );
inline long long read(){
long long x=0,f=1;
char ch = getchar();
for(;ch<'0'||ch>'9';ch =getchar() ) if(ch == '-') f= -1;
for(;ch>='0'&&ch<='9';ch = getchar()) x = (x<<3)+(x<<1)+ch-'0';
return x*f;
}
int a[maxs];
int f[maxs];
int t[maxs];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
f[i]=1;
for(int j=1;j<i;j++) if(a[i]>a[j])
f[i]=max(f[i],f[j]+1);
}
int ans,tmp;
for(int del=1;del<=n;del++){
for(int i=1;i<=n;i++) t[i]=inf;
ans = 0 ;
for(int j=1;j<=n;j++)
{
if(j==del)continue;
if( t[f[j]-1]< a[j] ) tmp = f[j];
else tmp = f[j]-1;
t[tmp]=min(t[tmp],a[j]);
ans ^= (tmp*tmp);
}
printf("%d%c",ans,(del==n)?'\n':' ');
}
}
return 0;
}