2020 年 “遊族杯” C.Coronavirus Battle 三維LIS

好菜啊 寫個近乎板子的題寫了個把小時  

這題看題意就知道最後的答案是求 ans[i] 表示以i點結尾的最長lis的長度   數據是隨機的大概率不會有重複的點  但是爲了保險我還是去了一下重  z這一維由於要用樹狀數組 我就離散了一下 然後套cdq板子就行了

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int K = 1e5+10;
typedef unsigned long long ull;
int lans[N];
ull has[K];
unsigned long long k1, k2;
unsigned long long CoronavirusBeats() {
unsigned long long k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
struct node{
	ull x,y,z;
	int ans,w,id;
};
node a[N],b[N];
int n;
int k,_n;
bool cmpx(node u,node v){
	if(u.x==v.x)
    {
        if(u.y==v.y)
            return u.z<v.z;
        return u.y<v.y;
    }
    return u.x<v.x;
}
bool cmpy(node p,node q){
	if(p.y==q.y) return p.z<q.z;
	return p.y<q.y;
}
int d[K];
void add(int x,int val){
	while(x<=k){
		d[x]=max(d[x],val);
		x+=x&-x;
	}
}
int query(int x){
	int ret = -1;
	while(x){
		ret=max(ret,d[x]);
		x-=x&-x;
	}return ret;
}
void del(int x){
	while(x<=k){
		d[x]=-1;
		x+=x&-x;
	}
}
void CDQ(int L,int R){
	if(L==R) return;
	int M=L+R>>1;
	CDQ(L,M);
	sort(a+L,a+1+M,cmpy);
	sort(a+1+M,a+1+R,cmpy);
	int i=M+1,j=L;
	for(;i<=R;i++){
		while(a[j].y<=a[i].y&&j<=M) add(a[j].z,a[j].ans),j++;
		//if(L==1&&R==2) 
		a[i].ans=max(a[i].ans,query(a[i].z)+1);
	}
	for(i=L;i<j;i++) del(a[i].z);
	sort(a+1+M,a+1+R,cmpx);
	CDQ(M+1,R);
}
int main(){
	scanf("%d",&_n);
	cin>>k1>>k2;
	//printf("%d %d\n",_n,k);
	int tot = 0;
	for (int i = 1; i <= _n; ++i) {
		b[i].id=i;
		b[i].x = CoronavirusBeats();
		b[i].y = CoronavirusBeats();
		b[i].z = CoronavirusBeats();
		has[++tot]=b[i].z;
	}
	sort(has+1,has+1+tot);
	k=unique(has+1,has+1+tot)-has-1;
	for(int i = 1; i <= k; i++) d[i]=-1;
	for(int i = 1; i <= _n; i++)
		b[i].z=lower_bound(has+1,has+1+k,b[i].z)-has;
	int c = 0;
	sort(b+1,b+1+_n,cmpx);
	for(int i = 1; i <= _n; i++){
		c++;
        if(b[i].x!=b[i+1].x || b[i].y!=b[i+1].y || b[i].z!=b[i+1].z || i==n)
        a[++n]=b[i],a[n].w=c,c=0;
	}
	CDQ(1,n);
	sort(a+1,a+1+n,cmpx);
	/*for(int i = 1; i <= n; i++){
		cout<<"x="<<a[i].x<<" y="<<a[i].y<<" z="<<a[i].z<<endl;
		printf("a[%d].ans=%d a[%d].w=%d\n",i,a[i].ans,i,a[i].w);
	}*/
	int mx = 0,p = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < a[i].w; j++)
		lans[b[p+j].id]=a[i].ans;
		p+=a[i].w;
	}
	for(int i = 1; i <= _n; i++)
	mx=max(mx,lans[i]);
	printf("%d\n",mx+1);
	for(int i = 1; i < _n; i++){
		printf("%d ",lans[i]);
	}
	printf("%d\n",lans[_n]);
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章