20pts求调!!!

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

qzwzzhengpengda @ 2024-11-23 17:31:52

我只是小小copy一下的P3369代码,小小改了一下就只剩下20pts qwq (help me!!)

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+10;
int n;
int cnt,root;
struct node{
    int left,right;
    int size;
    int date,value;
}e[MAXN];
void update(int x)
{
    e[x].size=e[e[x].left].size+e[e[x].right].size+1;
}
void right_rorate(int &u)
{
    int v=e[u].left;
    e[u].left=e[v].right;
    e[v].right=u;
    e[v].size=e[u].size;
    update(u);
    u=v;
}
void left_rorate(int &u)
{
    int v=e[u].right;
    e[u].right=e[v].left;
    e[v].left=u;
    e[v].size=e[u].size;
    update(u);
    u=v;
}
void insert(int &u,int date)
{
    if(u==0)
    {
        cnt++;
        u=cnt;
        e[u].size=1;
        e[u].date=date;
        e[u].value=rand();
        return ;
    }
    e[u].size++;
    if(date>=e[u].date)
        insert(e[u].right,date);
    else 
        insert(e[u].left,date);
    if(e[u].left!=0&&e[u].value>e[e[u].left].value)
        right_rorate(u);
    if(e[u].right!=0&&e[u].value>e[e[u].right].value)
        left_rorate(u);
    update(u);
}
void erase(int &u,int date)
{
    e[u].size--;
    if(e[u].date==date)
    {
        if(e[u].left==0&&e[u].right==0)
        {
            u=0;
            return;
        }
        if(e[u].right==0||e[u].left==0)
        {
            u=e[u].left+e[u].right;
            return ;
        }
        if(e[e[u].left].value<e[e[u].right].value)
        {
            right_rorate(u);
            erase(e[u].right,date);
            return ;
        }
        else //if(e[e[u].right].value<e[e[u].left].value)
        {
            left_rorate(u);
            erase(e[u].left,date);
            return ;
        }
    }
    if(e[u].date>=date)
        erase(e[u].left,date);
    else
        erase(e[u].right,date);
    update(u);
}
int rak(int now,int date)
{
    if(now==0)
    {
        return 0;
    }
    if(date>e[now].date)
    {
        return e[e[now].left].size+1+rak(e[now].right,date);
    }
    return rak(e[now].left,date);
}
int find(int u,int r)
{
    if(r==e[e[u].left].size+1)
        return e[u].date;
    if(r>e[e[u].left].size+1)
        return find(e[u].right,r-e[e[u].left].size-1);
    else
        return find(e[u].left,r);
}
int query_pre(int u,int date)
{
    if(u==0)
        return 0;
    if(e[u].date>=date)
        return query_pre(e[u].left,date);
    int v=query_pre(e[u].right,date);
    if(v==0)
        return e[u].date;
    return v;
}
int query_suf(int u,int date)
{
    if(u==0)
        return 0;
    if(e[u].date<=date)
        return query_suf(e[u].right,date);
    int v=query_suf(e[u].left,date);
    if(v==0)
        return e[u].date;
    return v;
}
int main()
{
//  freopen("P3369_5.in","r",stdin);
//  freopen("P3360.out","w",stdout);
    int m;
    srand(19620817);
    scanf("%d%d",&n,&m);
    int x;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        insert(root,x);
    }
    int op;
    int last=0;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&op,&x);
        x^=last;
        if(op==1)
            insert(root,x);
        if(op==2)
            erase(root,x);
        /*if(op<=2)
            continue;       */
        if(op==3)
            last=(rak(root,x)+1),sum^=last;
        if(op==4)
            last=find(root,x),sum^=last;
        if(op==5)
            last=query_pre(root,x),sum^=last;
        if(op==6)
            last=query_suf(root,x),sum^=last;

    }
    printf("%d\n",sum);
    return 0;
}

by wuyuhann123456789 @ 2024-11-27 21:17:21

int sum=0;

下面那一行的m打成n


by qzwzzhengpengda @ 2024-11-27 21:18:16

数据太水了,这都有20pts


by Y_QWQ_Y @ 2024-12-14 11:21:54

不是,我不输入 n 都有 20 分?


|