题面

戳我

Sol

右偏树滑稽+并查集

再在全局开一个可删除的堆(priority_queue)

注意细节

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(3e5 + 10); IL ll Read(){
RG ll x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int n, a[_], fa[_], add, S[_], top, rt[_];
struct Right_Heap{ int fa, ls, rs, dis, val, tag; } t[_];
struct Heap{
priority_queue <int> A, B;
IL void Push(RG int x){ A.push(x); } IL void Del(RG int x){ B.push(x); } IL int Top(){ while(!B.empty() && A.top() == B.top()) A.pop(), B.pop(); return A.top(); }
} Q; IL void Update(RG int x){ t[x].dis = t[t[x].ls].dis + 1; } IL void Adjust(RG int x){ if(t[t[x].ls].dis > t[t[x].rs].dis) swap(t[x].ls, t[x].rs); } IL void Add(RG int x, RG int d){ if(!x) return; t[x].tag += d; t[x].val += d; } IL void Pushdown(RG int x){ if(!t[x].tag) return; Add(t[x].ls, t[x].tag); Add(t[x].rs, t[x].tag); t[x].tag = 0; } IL int Find(RG int x){ return fa[x] == x ? x : fa[x] = Find(fa[x]); } IL int Merge(RG int x, RG int y){
if(!x || !y) return x + y;
Pushdown(x); Pushdown(y);
if(t[x].val < t[y].val) swap(x, y);
RG int tmp = Merge(t[x].ls, y);
t[tmp].fa = x; t[x].ls = tmp;
Adjust(x); Update(x);
return x;
} IL void Pushall(RG int x){ for(RG int y = x; y; y = t[y].fa) S[++top] = y; while(top) Pushdown(S[top--]); } IL void Modify(RG int x, RG int d){
Pushall(x);
RG int tmp = Merge(t[x].ls, t[x].rs);
if(t[x].fa){
if(t[t[x].fa].ls == x) t[t[x].fa].ls = tmp;
else t[t[x].fa].rs = tmp;
for(RG int y = t[x].fa; y; y = t[y].fa) Adjust(y), Update(y);
}
t[tmp].fa = t[x].fa; t[x].fa = t[x].ls = t[x].rs = 0;
RG int fx = Find(x);
Q.Del(t[rt[fx]].val);
if(x == rt[fx]) rt[fx] = tmp; t[x].val += d;
rt[fx] = Merge(rt[fx], x); t[rt[fx]].fa = 0;
Q.Push(t[rt[fx]].val);
} IL void Query(RG int x){ Pushall(x); printf("%d\n", t[x].val + add); } int main(RG int argc, RG char* argv[]){
n = Read();
for(RG int i = 1; i <= n; ++i) t[i].val = Read(), Q.Push(t[i].val), fa[i] = rt[i] = i;
for(RG int m = Read(); m; --m){
RG char op[5]; RG int x, y, fx, fy;
scanf(" %s", op);
if(op[0] == 'U'){
x = Read(); y = Read(); fx = Find(x); fy = Find(y);
if(fx == fy) continue;
Q.Del(t[rt[fx]].val); Q.Del(t[rt[fy]].val);
fa[fx] = fy; rt[fy] = Merge(rt[fx], rt[fy]); t[rt[fy]].fa = 0;
Q.Push(t[rt[fy]].val);
}
else if(op[0] == 'A'){
if(op[1] == '1') x = Read(), y = Read(), Modify(x, y);
else if(op[1] == '2'){
x = Read(); y = Read(); fx = Find(x);
Q.Del(t[rt[fx]].val); Add(rt[fx], y); Q.Push(t[rt[fx]].val);
}
else x = Read(), add += x;
}
else{
if(op[1] == '1') x = Read(), Query(x);
else if(op[1] == '2') x = Read(), fx = Find(x), printf("%d\n", t[rt[fx]].val + add);
else printf("%d\n", Q.Top() + add);
}
}
return 0;
}

(右偏树)Bzoj2333: [SCOI2011]棘手的操作的更多相关文章

  1. BZOJ2333 [SCOI2011]棘手的操作 堆 左偏树 可并堆

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ2333 题意概括 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i ...

  2. [bzoj2333] [SCOI2011]棘手的操作 (可并堆)

    //以后为了凑字数还是把题面搬上来吧2333 发布时间果然各种应景... Time Limit: 10 Sec  Memory Limit: 128 MB Description 有N个节点,标号从1 ...

  3. 真--可并堆模板--BZOJ2333: [SCOI2011]棘手的操作

    n<=300000个点,开始是独立的,m<=300000个操作: 方法一:单点修改.查询,区间修改.查询?等等等等这里修改是块修改不是连续的啊,那就让他连续呗!具体方法:离线后,每次连接两 ...

  4. bzoj千题计划218:bzoj2333: [SCOI2011]棘手的操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=2333 上次那个是线段树,再发一个左偏树 维护两种左偏树 第一种是对每个联通块维护一个左偏树 第二种是 ...

  5. BZOJ2333 [SCOI2011]棘手的操作 【离线 + 线段树】

    题目 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边,连接第x个节点和第y个节点 A1 x v: 将第x个节点的权 ...

  6. bzoj千题计划217:bzoj2333: [SCOI2011]棘手的操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=2333 读入所有数据,先模拟一遍所有的合并操作 我们不关心联通块长什么样,只关心联通块内有谁 所以可以 ...

  7. bzoj2333 [SCOI2011]棘手的操作(洛谷3273)

    题目描述 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作:U x y: 加一条边,连接第x个节点和第y个节点A1 x v: 将第x个节点的权 ...

  8. 2019.01.17 bzoj2333: [SCOI2011]棘手的操作(启发式合并)

    传送门 启发式合并菜题. 题意:支持与连通块有关的几种操作. 要求支持连边,单点修改,连通块修改,全局修改和单点查值,连通块查最大值和全局最大值. 我们对每个连通块和答案用可删堆维护最大值,然后用启发 ...

  9. BZOJ2333:[SCOI2011]棘手的操作(Splay)

    Description 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边,连接第x个节点和第y个节点 A1 x v: ...

随机推荐

  1. 分布式服务dubbo使用

    SOA 服务框架dubbo 节点角色说明: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发现的注册中心. Monitor: ...

  2. 阿里巴巴Java开发规约插件地址

    Git地址: https://github.com/alibaba/p3c eclipse 安装地址: https://p3c.alibaba.com/plugin/eclipse/update

  3. Struts2 基本的ResultType 【学习笔记】

    在struts2-core.jar/struts-default.xml中,我们可以找到关于result-type的一些配置信息,从中可以看出struts2组件默认为我们提供了这 些result-ty ...

  4. Java中空串和null串的区别

    对于空串来说这是一个对象他被""这个对象给实例化了只是他的长度为0字符的内容为空. 而String变量中还可以存储一个特殊的值,这个是null,这个表示没有和其他的对象与这个变量相 ...

  5. PAT 1002. A+B for Polynomials

    思路:就是两个多项式做加法–指数相同的相加即可,输出的时候按照指数递减输出,并且系数为0的项不输出. AC代码 #include <stdio.h> #include <vector ...

  6. uva1343 IDA*

    这题需要用数组记录每个block的位置.启发函数:d+wa(8-当前最多相同个数)>maxd直接退出 AC代码: #include<cstdio> #include<cstri ...

  7. PV和UV的简单记录

    1.什么是PV值 PV(page view)即页面浏览量或点击量,是衡量一个网站或网页用户访问量.具体的说,PV值就是所有访问者在24小时(0点到24点)内看了某个网站多少个页面或某个网页多少次.PV ...

  8. CentOS下iptables持久化

    iptables规则持久化 设定防火墙规则 iptables -A INPUT -s 1.1.1.1/32 -p tcp -m tcp --dport 22 -j DROP iptables -A I ...

  9. linux 存储技术 部署iSCSI NFS Multipath多路径

    存储技术应用存储是根据不同的应用环境通过采取合理,安全,有效的方式将数据保存到某些介质上并能保证有效的访问另一方面,它是保证数据完整安全存放的方式或行为存储就是把这两方面结合起来,向客户提供一套数据存 ...

  10. 使用BEM命名规范来组织CSS代码

    BEM 是 Block(块) Element(元素) Modifier(修饰器)的简称 使用BEM规范来命名CSS,组织HTML中选择器的结构,利于CSS代码的维护,使得代码结构更清晰(弊端主要是名字 ...