fhqTLE求条

P3391 【模板】文艺平衡树

run_away @ 2024-03-27 19:37:27

不知道是什么原因#4#5 TLE。

#include<bits/stdc++.h>
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<21],*O=obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read(){int x=0,f=1;char c=getchar();while(c<48||c>57){if(c==45)f=0;c=getchar();}while(c>47&&c<58)x=(x<<3)+(x<<1)+(c^48),c=getchar();return f?x:-x;}
const int mod=1e9+7,maxn=1e6+5;
int n,m,root,l,r,p,cnt;
struct fhqtreap{int l,r,siz,val,key,tag;}treap[maxn];
inline int newnode(int u){treap[++cnt]={0,0,1,u,0,rand()|rand()<<15};return cnt;}
inline void pushdown(int u){
    if(!treap[u].tag)return;
    swap(treap[u].l,treap[u].r);
    treap[treap[u].l].tag^=1,treap[treap[u].r].tag^=1,treap[u].tag=0;
}
inline void split(int u,int x,int&l,int&r){
    if(!u){l=r=0;return;}
    if(treap[u].tag)pushdown(u);
    if(treap[treap[u].l].siz+1<=x)l=u,split(treap[u].r,x-treap[treap[u].l].siz-1,treap[u].r,r);
    else r=u,split(treap[u].l,x,l,treap[u].l);
    treap[u].siz=treap[treap[u].l].siz+treap[treap[u].r].siz+1;
}
inline int merge(int l,int r){
    if(!l||!r)return l+r;
    if(treap[l].key<treap[r].key){
        if(treap[l].tag)pushdown(l);
        treap[l].r=merge(treap[l].r,r);
        treap[l].siz=treap[treap[l].l].siz+treap[treap[l].r].siz+1;return l;
    }
    else{
        if(treap[r].tag)pushdown(r);
        treap[r].l=merge(l,treap[r].l);
        treap[r].siz=treap[treap[r].l].siz+treap[treap[r].r].siz+1;
        return r;
    }
}
inline void outputtreap(int u){
    if(treap[u].tag)pushdown(u);
    if(treap[u].l)outputtreap(treap[u].l);
    printf("%lld ",treap[u].val);
    if(treap[u].r)outputtreap(treap[u].r);
}
signed main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i){
        newnode(i);
        root=merge(root,i);
    }
    while(m--){
        int x=read(),y=read();
        split(root,y,l,r);
        split(l,x-1,l,p);
        treap[p].tag^=1;
        root=merge(merge(l,p),r);
    }
    outputtreap(root);
    return 0;
}

by koukilee @ 2024-03-27 19:41:27

orz


by weak_in_code @ 2024-03-27 19:51:29

orz


by run_away @ 2024-03-27 19:56:21

@koukilee ntm大紫大黑的别来叫了行不


by wjr_jok @ 2024-03-27 20:21:59

@run_away %%%


|