#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std ;
const int N=300010;
const int mod=1<<30;
struct P
{
int x,y,z;
P(){}
P(int xx,int yy,int zz){x=xx;y=yy;z=zz;}
bool operator <(const P &a)const{
if(x!=a.x) return x<a.x;
if(y!=a.y) return y>a.y;
return z>a.z;
}
}p[N];
struct Node{
int id,x,y,z;
Node(){}
Node(int id,int x,int y,int z):id(id),x(x),y(y),z(z){}
bool operator <(const Node &a)const{
if(y!=a.y) return y<a.y;
if(x!=a.x) return x>a.x;
else return z>a.z;
}
}node[N];
int dp[N],sum[N];
int n,m;
int pos[N];
int lowbit(int x){return x&(-x);}
void update(int x,int val)
{
for(;x<=m;x+=lowbit(x))
sum[x]=max(sum[x],val);
}
int query(int x)
{
int ans=0;
for(;x>0;x-=lowbit(x))
{
ans=max(ans,sum[x]);
}
return ans;
}
void Clear(int x){
for(;x<=m;x+=lowbit(x)){
sum[x]=0;
}
}
void cdq(int l,int r)
{
if(l>=r) return;
int mid=(l+r)>>1;
cdq(l,mid);
for(int i=l;i<=r;i++)
node[i]=Node(i,p[i].x,p[i].y,p[i].z);
sort(node+l,node+r+1);
for(int i=l;i<=r;i++)
{
int id=node[i].id;
if(id<=mid){
update(node[i].z,dp[id]);
}
else{
dp[id]=max(dp[id],query(node[i].z-1)+1);
}
}
for(int i=l;i<=r;i++)
if(node[i].id<=mid)
Clear(node[i].z);
cdq(mid+1,r);
}
const int C = ~(1 << 31);
const int M = (1 << 16) - 1;
int A,B;
int r() {
A = 36969 * (A & M) + (A >> 16);
B = 18000 * (B & M) + (B >> 16);
return (C & ((A << 16) + B)) % 1000000;
}
int main()
{
#ifdef DouBi
freopen("in.cpp","r",stdin);
#endif // gh546
while(scanf("%d%d%d%d",&m,&n,&A,&B)!=EOF)
{
if(n==0&&m==0&&A==0&&B==0) break;
int cnt=0;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z);
pos[cnt++]=p[i].z;
}
for(int i=m+1;i<=n+m;i++){
p[i].x=r(); p[i].y=r(); p[i].z=r();
pos[cnt++]=p[i].z;
}
n+=m;
sort(p+1,p+1+n);
sort(pos,pos+cnt);
m=unique(pos,pos+cnt)-pos;
for(int i=1;i<=n;i++)
{
p[i].z=lower_bound(pos,pos+m,p[i].z)-pos+1;
}
for(int i=0;i<=m;i++) sum[i]=0;
for(int i=1;i<=n;i++) dp[i]=1;
cdq(1,n);
int ans=0;
for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
printf("%d\n",ans);
}
return 0;
}
cdq
最新推荐文章于 2024-02-26 17:43:38 发布