【BZOJ】3159决战-LCT

题解

此题的一种经典做法:套两颗LCT,一颗维护权值,一颗维护形态。
形态树里的每一个节点都有一个对应的权值树里的点。
对于值的区间翻转,只翻转权值树。其他操作则两棵树一起操作。
在形态树中操作时,对于节点之间关系的修改,对应权值中的点可以通过bst找k大完成。

代码

#include<cstdio>
 #include<algorithm>
 #include<cstring> 
 #include<cctype>
 #include<cstdlib>
 using namespace std;
 typedef long long ll;
 const int N=5e4+10;
 const ll inf=1LL<<60;
 int n,m,R;
 char s[12];

 inline int rd()
 {
    char ch=getchar();int x=0,f=1;
    while(!isdigit(ch)){
  if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^48);ch=getchar();}
    return x*f;
 }

 struct Ta{
    struct Node{
        Node *ch[2],*f;int sz,rv;
        ll ad,v,mn,mx,sum;
        void reverse(){
            rv^=1;swap(ch[0],ch[1]);
        }
        void update(){
            sz=ch[0]->sz+1+ch[1]->sz;
            sum=ch[0]->sum+v+ch[1]->sum;
            mn=min(min(ch[0]->mn,ch[1]->mn),v);
            mx=max(max(ch[0]->mx,ch[1]->mx),v); 
        } 
        void change(int w){
            ad+=w;v+=w;mn+=w;mx+=w;sum+=1ll*sz*w; 
        }
        void pushdown(Node *null){
            if(rv){
                if(ch[0]!=null) ch[0]->reverse();
                if(ch[1]!=null) ch[
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值