cdq

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值