luogu 3919
主席树
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string> using namespace std; #define LL long long #define gc getchar()
inline int read() {int x = , f = ; char c = gc;
while(c < '' || c > '') {if(c == '-') f = -; c = gc;};
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x * f;}
inline LL read_LL() {LL x = ; char c = gc; while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc; return x;}
#undef gc const int N = 1e6 + ; int W[N * * ], Lson[N * * ], Rson[N * * ];
int Root[N];
int Hjt;
int n, q; void Build_tree(int l, int r, int &rt) {
rt = ++ Hjt;
if(l == r) {
W[rt] = read();
return ;
}
int mid = (l + r) >> ;
Build_tree(l, mid, Lson[rt]), Build_tree(mid + , r, Rson[rt]);
} void Fill(int x, int y) {
W[x] = W[y], Lson[x] = Lson[y], Rson[x] = Rson[y];
} void Poi_G(int &rt, int l, int r, int x, int val) {
Fill(++ Hjt, rt);
rt = Hjt;
if(l == r) {
W[rt] = val;
return ;
}
int mid = (l + r) >> ;
if(x <= mid) Poi_G(Lson[rt], l, mid, x, val);
else Poi_G(Rson[rt], mid + , r, x, val);
} int Ans; void Poi_A(int rt, int l, int r, int x) {
if(l == r) {
Ans = W[rt];
return ;
}
int mid = (l + r) >> ;
if(x <= mid) Poi_A(Lson[rt], l, mid, x);
else Poi_A(Rson[rt], mid + , r, x);
} int main() {
n = read(), q = read();
Build_tree(, n, Root[]);
for(int i = ; i <= q; i ++) {
int v = read(), opt = read(), loc = read(), val;
if(opt == ) val = read();
if(opt == ) {
Root[i] = Root[v];
Poi_G(Root[i], , n, loc, val);
} else {
Poi_A(Root[v], , n, loc);
Root[i] = Root[v];
cout << Ans << "\n";
}
}
return ;
}
luogu 3919的更多相关文章
- [Luogu 3919]【模板】可持久化数组(可持久化线段树/平衡树)
Description 如题,你需要维护这样的一个长度为 N 的数组,支持如下几种操作 在某个历史版本上修改某一个位置上的值 访问某个历史版本上的某一位置的值 此外,每进行一次操作(对于操作2,即为生 ...
- [LUOGU]3919 【模板】可持久化数组
用可持久化线段树维护可持久化数组.可持久化线段树见之前发的主席树模板 #include <iostream> #include <cstdio> #include <cs ...
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ...
- luogu p1268 树的重量——构造,真正考验编程能力
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...
- [luogu P2170] 选学霸(并查集+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...
- [luogu P2647] 最大收益(贪心+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...
- Luogu 考前模拟Round. 1
A.情书 题目:http://www.luogu.org/problem/show?pid=2264 赛中:sb题,直接暴力匹配就行了,注意一下读入和最后一句话的分句 赛后:卧槽 怎么只有40 B.小 ...
- luogu P2580 于是他错误的点名开始了
luogu P2580 于是他错误的点名开始了 https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边 ...
- CJOJ 1331 【HNOI2011】数学作业 / Luogu 3216 【HNOI2011】数学作业 / HYSBZ 2326 数学作业(递推,矩阵)
CJOJ 1331 [HNOI2011]数学作业 / Luogu 3216 [HNOI2011]数学作业 / HYSBZ 2326 数学作业(递推,矩阵) Description 小 C 数学成绩优异 ...
随机推荐
- 2..net core 和.net framework 版本
同一台机器上可以安装多个版本的.net core runtime.比如: 每个.net core项目都可以指定自己所用的版本,所以改变某个项目的target version不会影响到其他的.安装新的r ...
- 笔记 - C#从头开始构建编译器 - 1
视频与PR:https://github.com/terrajobst/minsk/blob/master/docs/episode-01.md 作者是 Immo Landwerth(https:// ...
- [转载]C++名字空间
[转载]C++名字空间 之前这个概念没搞清楚,最近又遇到了,这里记录一下. 下面的资料讲的比较深入浅出: http://c.biancheng.net/view/2193.html http://c. ...
- openstack-neutron(2)
VXLAN 独立于底层的网络拓扑:反过来,两个 VTEP 之间的底层 IP 网络也独立于 VXLAN.VXLAN 数据包是根据外层的 IP header 路由的,该 header 将两端的 VTEP ...
- UI5-技术篇-Hybrid App-1-Barcode扫描
参考资料: https://www.w3cschool.cn/cordova/cordova_overview.html https://blogs.sap.com/2017/01/03/sapui5 ...
- SAP-参数(条件表)配置教程–GS01/GS02/GS03
转载:http://www.baidusap.com/abap/others/2849 在SAP开发中,某段代码运行可能需要满足某个条件,通常解决办法有两种:一种是在代码中写死限制条件,此种方式当限制 ...
- fatfs源码阅读
使用fatfs文件的第一步,就是调用F_mount函数注册一个工作空间. F_mount函数的原型如下: 第一个参数根据网上大神的答复,是外设类型,如果是sd卡就是0,flash等等其他的外设就是其他 ...
- springboot学习入门简易版四---springboot2.0静态资源访问及整合freemarker视图层
2.4.4 SpringBoot静态资源访问(9) Springboot默认提供静态资源目录位置需放在classpath下,目录名需要符合如下规则 /static /public /resourc ...
- ipv4与ipv6 Inet4Address类和Inet6Address类
在设置本地IP地址的时候,一些人会疑惑IPv4与IPv6的区别是什么?下面由学习啦小编为你分享ipv4与ipv6的区别的相关内容,希望对大家有所帮助. ipv4与ipv6的区别 在windows 7以 ...
- hive之建立分区表和分区
1. 建立分区表 create table 单分区表:其中分区字段是partdate,注意分区字段不能和表字段一样,否则会报重复的错 create table test_t2(words string ...