什么恶心东西啊,又水又烦

两个可并堆维护即可

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); (a) <= (c); ++(a))
#define nR(a,b,c) for(register int a = (b); (a) >= (c); --(a))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define ll long long
#define u32 unsigned int
#define u64 unsigned long long #define ON_DEBUGG #ifdef ON_DEBUGG #define D_e_Line printf("\n----------\n")
#define D_e(x) cout << (#x) << " : " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#include <ctime>
#define TIME() fprintf(stderr, "\ntime: %.3fms\n", clock() * 1000.0 / CLOCKS_PER_SEC) #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
//char buf[1 << 21], *p1 = buf, *p2 = buf;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) #endif using namespace std;
struct ios{
template<typename ATP>inline ios& operator >> (ATP &x){
x = 0; int f = 1; char ch;
for(ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
while(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = getchar();
x *= f;
return *this;
}
}io; template<typename ATP>inline ATP Max(ATP a, ATP b){
return a > b ? a : b;
}
template<typename ATP>inline ATP Min(ATP a, ATP b){
return a < b ? a : b;
}
template<typename ATP>inline ATP Abs(ATP a){
return a < 0 ? -a : a;
} const int N = 3e5 + 7; #define int long long
int n, tagAll, root; #define ls ch[x][0]
#define rs ch[x][1] int a[N];
struct LeftTree{
int ch[N][2], val[N], tag[N], fa[N], dis[N]; inline void Clear(int x) {
ch[x][0] = ch[x][1] = fa[x] = 0;
} inline int Sum(int x) {
int sum = 0;
for(x = fa[x]; x; x = fa[x]) sum += tag[x];
return sum;
} inline void Pushdown(int x) {
if(!tag[x]) return;
if(ls) val[ls] += tag[x], tag[ls] += tag[x];
if(rs) val[rs] += tag[x], tag[rs] += tag[x];
tag[x] = 0;
} inline int Merge(int x, int y) {
if(!x || !y) return x | y;
if(val[x] < val[y]) Swap(x, y);
Pushdown(x);
rs = Merge(rs, y);
fa[ls] = fa[rs] = x;
if(dis[rs] > dis[ls]) Swap(ls, rs);
dis[x] = dis[rs] + 1;
return x;
} inline int Find(int x) {
while(fa[x]) x = fa[x];
return x;
} inline int Del(int x) {
Pushdown(x);
int father = fa[x];
int rt = Merge(ls, rs);
fa[rt] = father;
if(father) ch[father][x == ch[father][1]] = rt;
while(father){
if(dis[ch[father][0]] < dis[ch[father][1]])
Swap(ch[father][0], ch[father][1]);
if(dis[father] == dis[ch[father][1]] + 1)
return root;
dis[father] = dis[ch[father][1]] + 1;
rt = father;
father = fa[father];
}
return rt;
} inline int Push(int x, int w) {
int father = Find(x);
if(father == x){
if(!ls && !rs){
val[x] += w;
return x;
}
else{
if(ls)
father = ls;
else
father = rs;
}
}
Del(x);
val[x] += w + Sum(x);
Clear(x);
return Merge(Find(father), x);
} int q[N];
inline int Build() {
int h = 0, t = 0;
R(i,1,n){
q[++t] = i;
}
while(h != t){
int x = q[++h];
if(h == N - 5) h = 0;
int y = q[++h];
if(h == N - 5) h = 0;
q[++t] = Merge(x, y);
if(t == N - 5) t = 0;
}
return q[t];
}
}T, H; #undef int
int main() {
#define int long long
//FileOpen();
io >> n;
T.dis[0] = H.dis[0] = -1;
R(i,1,n){
io >> a[i];
T.val[i] = H.val[i] = a[i];
}
root = H.Build();
int m;
io >> m;
char opt[7];
while(m--){
scanf("%s", opt + 1);
if(opt[1] == 'U'){
int x, y;
io >> x >> y;
x = T.Find(x), y = T.Find(y);
if(x == y) continue;
int tmp = T.Merge(x, y);
if(tmp == x)
root = H.Del(y);
else
root = H.Del(x);
}
else if(opt[1] == 'A' && opt[2] == '1'){
int x, w;
io >> x >> w;
root = H.Del(T.Find(x));
int tmp = T.Push(x, w);
H.val[tmp] = T.val[tmp];
H.Clear(tmp);
root = H.Merge(root, tmp);
}
else if(opt[1] == 'A' && opt[2] == '2'){
int x, w;
io >> x >> w;
int father = T.Find(x);
root = H.Del(father);
T.val[father] += w;
T.tag[father] += w;
H.val[father] = T.val[father];
H.Clear(father);
root = H.Merge(root, father);
}
else if(opt[1] == 'A' && opt[2] == '3'){
int w;
io >> w;
tagAll += w;
}
else if(opt[1] == 'F' && opt[2] == '1'){
int x;
io >> x;
printf("%lld\n", T.val[x] + tagAll + T.Sum(x));
}
else if(opt[1] == 'F' && opt[2] == '2'){
int x;
io >> x;
printf("%lld\n", T.val[T.Find(x)] + tagAll);
}
else{
printf("%lld\n", H.val[root] + tagAll);
}
} return 0;
}

Luogu P3273 [SCOI2011]棘手的操作(左偏树)的更多相关文章

  1. 洛谷P3273 [SCOI2011] 棘手的操作 [左偏树]

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

  2. 洛谷.3273.[SCOI2011]棘手的操作(左偏树)

    题目链接 还是80分,不是很懂. /* 七个操作(用左偏树)(t2表示第二棵子树): 1.合并:直接合并(需要将一个t2中原有的根节点删掉) 2.单点加:把这个点从它的堆里删了,加了再插入回去(有负数 ...

  3. 2333: [SCOI2011]棘手的操作[离线线段树]

    2333: [SCOI2011]棘手的操作 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2325  Solved: 909[Submit][Stat ...

  4. Luogu P4331 [BOI2004]Sequence 数字序列 (左偏树论文题)

    清晰明了%%% Fairycastle的博客 个人习惯把size什么的存在左偏树结点内,这样在外面好写,在里面就是模板(只用修改update). 可以对比一下代码(好像也差不多-) MY CODE # ...

  5. P3273 [SCOI2011]棘手的操作

    吐槽 上午风浔凌julao问我的神题 操作又多又毒瘤又棘手... 然后bzoj题号正好是2333,2333333333 思路 貌似只有我是这么写的 线段树合并, 每个线段树存每个连通块的信息,维护点的 ...

  6. 洛谷P3273 [SCOI2011]棘手的操作

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

  7. bzoj2333[SCOI2011]棘手的操作 洛谷P3273 [SCOI2011]棘手的操作

    2333? 先记一下吧,这题现在全部都是照着题解做的,因为怎么改都改不出来,只好对着题解改,以后还要再做过 以后再也不用指针了!太恶心了!空指针可不止直接特判那么简单啊,竟然还要因为空指针写奇怪的分类 ...

  8. luogu 2483 K短路 (可持久化左偏树)

    题面: 题目大意:给你一张有向图,求1到n的第k短路 $K$短路模板题 假设整个图的边集为$G$ 首先建出以点$n$为根的,沿反向边跑的最短路树,设这些边构成了边集$T$ 那么每个点沿着树边走到点$n ...

  9. 左偏树 / 非旋转treap学习笔记

    背景 非旋转treap真的好久没有用过了... 左偏树由于之前学的时候没有写学习笔记, 学得也并不牢固. 所以打算写这么一篇学习笔记, 讲讲左偏树和非旋转treap. 左偏树 定义 左偏树(Lefti ...

随机推荐

  1. Spring中的Bean作用域

    概述 scope用来声明容器中的对象所应该处的限定场景或者说该对象的存活时间,即容器在对象进入其 相应的scope之前,生成并装配这些对象,在该对象不再处于这些scope的限定之后,容器通常会销毁这些 ...

  2. JVM 输出 GC 日志导致 JVM 卡住,我 TM 人傻了

    本系列是 我TM人傻了 系列第七期[捂脸],往期精彩回顾: 升级到Spring 5.3.x之后,GC次数急剧增加,我TM人傻了:https://zhuanlan.zhihu.com/p/3970425 ...

  3. 一张图进阶 RocketMQ - NameServer

    前言 「三此君看了好几本书,看了很多遍源码整理的 一张图进阶 RocketMQ 图片链接,关于 RocketMQ 你只需要记住这张图!觉得不错的话,记得点赞关注哦.」 一张图进阶 RocketMQ 图 ...

  4. c# sqlsugar,hisql,freesql orm框架全方位性能测试对比 sqlserver 性能测试

    在2022年1月份本人做过一次sqlsugar,hisql,freesql三个框架的性能测试,上次主要是测的sqlserver下的常规插入(非bulkcopy的方式数据插入),hisql与目前比较流行 ...

  5. Python Excel 操作

    1.Excel Code import os import time import re import win32com.client def dealpath(pathname='') -> ...

  6. 一图读懂k8s informer client-go

    概述 为什么要有k8s informer 我们都知道可以使用k8s的Clientset来获取所有的原生资源对象,那么怎么能持续的获取集群的所有资源对象,或监听集群的资源对象数据的变化呢?这里不需要轮询 ...

  7. .NET6接入Skywalking链路追踪完整流程

    一.Skywalking介绍 Skywalking是一款分布式链路追踪组件,什么是链路追踪? 随着微服务架构的流行,服务按照不同的维度进行拆分,一次请求往往需要涉及到多个服务.互联网应用构建在不同的软 ...

  8. 关于android里activity之间利用button组件使用intent跳转页面

    在需要跳转的activity 中 添加 Button button = findViewById(R.id.login);button.setOnClickListener(new View.OnCl ...

  9. 【python基础】第11回 数据类型内置方法 02

    本章内容概要 列表内置方法 字典内置方法 元组内置方法 集合内置方法 可变类型与不可变类型 本章内容详细 1.列表内置方法 list 列表在调用内置方法之后不会产生新的值 1.1 统计列表中的数据值的 ...

  10. bat-winget-win平台的软件包管理器

    win10 1709版本以后 引入的包管理器,如果不可用 需要 更新一下 应用安装程序. winget命令的功能  常用的就  安装 卸载 更新  . 卸载 使用中如果提示 策略 不允许,可执行下面命 ...