题面

戳我

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. [Python Study Notes]CS架构远程访问获取信息--SERVER端

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  2. IDEA的优质使用博客资源

    intelliJ idea 使用技巧&方法 IntelliJ IDEA 常用设置讲解 IntelliJ IDEA 详细图解最常用的配置 ,适合刚刚用的新人. IntelliJ IDEA 常见文 ...

  3. css scale 元素放大缩小效果

    <style> .trans-scale { width: 300px; height:300px; margin:100px auto; background:#99F; transit ...

  4. dedecms实现编辑文章时不自动修改发布时间

    dedecms默认编辑文章时自动修改文章的发布时间,如何让它不自动修改发布时间呢? 找到后台编辑文章的模板文件稍作调整即可. 文件/dede/templets/artical_edit.htm 把 $ ...

  5. 谈谈语音通信中的各种tone

    今天谈的这个主题(tone)存在于我们的日常打电话过程中.先举两个场景:1,你拿起固话话筒准备打电话,按电话号码前先从话筒里听到"嗡"的连续音,这叫dial tone(拨号音,表示 ...

  6. Mac下PyCharm快捷键大全

    Mac键盘符号和修饰键说明 ⌘ Command ⇧ Shift ⌥ Option ⌃ Control ↩︎ Return/Enter ⌫ Delete ⌦ 向前删除键(Fn+Delete) ↑ 上箭头 ...

  7. git ssh 配置

    创建并切换到 ~/.ssh(存在就直接切换过去) 运行 ssh-keygen 创建 rsa 文件 复制 .pub 的文件内容,添加到网站的公钥列表 Git\etc\ssh\ssh_config 中添加 ...

  8. 以kaggle-titanic数据为基础的完整的机器学习

    1. 引入所有需要的包 # -*- coding:utf-8 -*- # 忽略警告 import warnings warnings.filterwarnings('ignore') # 引入数据处理 ...

  9. Shiro笔记--shiroFilter权限过滤

    1.shiro中shiroFilter中的一些配置页面的过滤权限 <!--名字必须和web.xml里面的filter-name一样--> <bean id="shiroFi ...

  10. LeetCode第五天

    leetcode 第五天 2018年1月6日 22.(566) Reshape the Matrix JAVA class Solution { public int[][] matrixReshap ...