为什么会这样

P6136 【模板】普通平衡树(数据加强版)

功在不舍 @ 2020-03-02 17:11:22

FHQ Treap全部RE

然而本地能够运行得到正确结果

#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<time.h>
using namespace std;
int n,m,last,p,q,ans,x,y,tmp,z;

    int all,root,size[2000000],pri[2000000],val[2000000],ch[2000000][2];
    inline int newnode(int v){val[++all]=v;size[all]=1;pri[all]=rand();return all;}
    inline int updata(int x){size[x]=size[ch[x][0]]+size[ch[x][1]]+1;}
    inline int merge(int x,int y){
        if(!x||!y) return x+y;
        if(pri[x]>pri[y]){
            ch[x][1]=merge(ch[x][1],y);
            updata(x);return x;
        }else{
            ch[y][0]=merge(x,ch[y][0]);
            updata(y);return y;
        }
    }
    inline void split(int now,int k,int &x,int &y){
        if(!now)x=y=0;
        else{
            if(val[now]<=k)x=now,split(ch[now][1],k,ch[now][1],y);
            else y=now,split(ch[now][0],k,x,ch[now][0]);
            updata(now);
        }
    }
    inline int kth(int now,int k){
        while(now){
            if(k<=size[ch[now][0]])now=ch[now][0];
            else {
                k-=(size[ch[now][0]]+1);
                if(k<=0)return now;
                now=ch[now][1];
            }
        }
    }
    inline void insert(int v){
        split(root,v,x,y);
        root=merge(merge(x,newnode(v)),y);
    }
    inline void del(int v){
        split(root,v,x,z);
        split(x,v-1,x,y);
        y=merge(ch[y][0],ch[y][1]);
        root=merge(merge(x,y),z);
    }
    inline int rank(int v){
        split(root,v-1,x,y);
        tmp=size[x]+1;
        root=merge(x,y);
        return tmp;
    }
    inline int prefix(int v){
        split(root,v-1,x,y);
        tmp=val[kth(x,size[x])];
        root=merge(x,y);
        return tmp;
    }
    inline int suffix(int v){
        split(root,v,x,y);
        tmp=val[kth(y,1)];
        root=merge(x,y);
        return tmp;
    }

inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
//  freopen("t1.in","r",stdin);
    n=read();m=read();
    for(int i=1;i<=n;i++)p=read(),insert(p);
    for(int i=1;i<=m;i++)
    {
        p=read();q=read();q^=last;
        if(p==1)insert(q);
        else if(p==2)del(q);
        else if(p==3)last=rank(q),ans^=last;
        else if(p==4)last=val[kth(root,q)],ans^=last;
        else if(p==5)last=prefix(q),ans^=last;
        else if(p==6)last=suffix(q),ans^=last;
    }
    cout<<ans<<endl;
    return 0;
}

by 功在不舍 @ 2020-03-02 17:23:42

@dengyaotriangle 太谢谢您了!真的是这个问题

这都行我醉了第一回遇见


上一页 |