cogs 2554. [福利]可持久化线段树
题目链接
题解
没有
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
inline int read () {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9'){if(c=='-')f=-1; c=getchar();}
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x*f;
}
const int maxn = 100007;
int n,m,a[maxn],tot = 1,root[maxn];
struct Chairman_Tree {
int ch[2],num ;
} ;
Chairman_Tree t[maxn << 4];
#define lc t[x].ch[0]
#define rc t[x].ch[1]
inline void update(int x) { t[x].num = std::max(t[lc].num,t[rc].num); }
void build(int & x,int l,int r) {
x = ++ tot;
if(l == r) {
t[x].num = a[l];return ;
}
int mid = l + r >> 1;
build(lc,l,mid); build(rc,mid+1,r);return ;
update(x) ;
}
int query(int x,int l,int r,int L,int R) {
if(l == r) return t[x].num;
int mid = l + r >>1;
int ret = 0;
if(mid >= L) ret = std::max(ret,query(lc,l,mid,L,R)) ;
if(mid < R) ret = std::max(ret,query(rc,mid+1,r,L,R)) ;
return ret ;
}
void modify(int pre,int &x,int l,int r,int pos,int w) {
t[x = ++tot] = t[pre];
if(l == r) {
t[x].num = w;return ;
}
int mid = l + r >> 1;
if(pos <= mid) modify(t[pre].ch[0],lc,l,mid,pos,w);
else modify(t[pre].ch[1],rc,mid + 1,r,pos,w);
update(x);
}
int main () {
freopen("longterm_segtree.in","r",stdin);
freopen("longterm_segtree.out","w",stdout);
n = read(),m = read(); int tmp = 1;
for(int i = 1;i <= n;++ i) a[i] = read();
build(root[1],1,n);
for(int T,op,a,b,i = 1;i <= m;++ i) {
op = read(),T = read();
if(op == 1) {
a = read(),b = read();
modify(root[T],root[++tmp],1,n,a,b);
}
else {
a = read(),b = read();//,root[i] = root[T];
printf("%d\n",query(root[T],1,n,a,b));
}
}
return 0;
}
cogs 2554. [福利]可持久化线段树的更多相关文章
- AC日记——[福利]可持久化线段树 cogs 2554
2554. [福利]可持久化线段树 ★★☆ 输入文件:longterm_segtree.in 输出文件:longterm_segtree.out 简单对比时间限制:3 s 内存限制:2 ...
- cogs2554 [福利]可持久化线段树
cogs2554 [福利]可持久化线段树 原题链接 每次修改复制一遍就行了... 1A!!! // It is made by XZZ #include<cstdio> #include& ...
- YSZOJ:#247. [福利]可持久化线段树 (最适合可持久化线段树入门)
题目链接:https://syzoj.com/problem/247 解题心得: 可持久化线段树其实就是一个线段树功能的加强版,加强在哪里呢?那就是如果一颗普通的线段树多次修改之后还能知道最开始的线段 ...
- [COGS2554][SYZOJ247][福利]可持久化线段树
思路: 主席树模板. 注意内存的分配,原始的线段树有$2n$个结点,每次更新时最多增加$log(n)$个结点,总共有$q$次询问,所以存储结点的数组大小为$2N+q log(n)$. #include ...
- PYOJ 44. 【HNSDFZ2016 #6】可持久化线段树
#44. [HNSDFZ2016 #6]可持久化线段树 统计 描述 提交 自定义测试 题目描述 现有一序列 AA.您需要写一棵可持久化线段树,以实现如下操作: A v p x:对于版本v的序列,给 A ...
- 【BZOJ-3673&3674】可持久化并查集 可持久化线段树 + 并查集
3673: 可持久化并查集 by zky Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 1878 Solved: 846[Submit][Status ...
- 【BZOJ-2653】middle 可持久化线段树 + 二分
2653: middle Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1298 Solved: 734[Submit][Status][Discu ...
- HDU 4866 Shooting(持久化线段树)
view code//第二道持久化线段树,照着别人的代码慢慢敲,还是有点不理解 #include <iostream> #include <cstdio> #include & ...
- 【BZOJ-3653】谈笑风生 DFS序 + 可持久化线段树
3653: 谈笑风生 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 628 Solved: 245[Submit][Status][Discuss] ...
随机推荐
- 【ZJ选讲·钻石游戏】
N×M的棋盘(M,N<=500)中,每个格子有一个颜色(颜色数1~9) P次操作(P<=1000),每次给出两个相邻的位置(保证颜色不同,两个格子有一条公共边),把这两个格子交换. 定 ...
- codeforces902B. Coloring a Tree
B. Coloring a Tree 题目链接: https://codeforces.com/contest/902/problem/B 题意:给你一颗树,原先是没有颜色的,需要你给树填色成指定的样 ...
- CI框架浅析
CI框架浅析(全篇) 业余花了点时间看看CodeIgniter框架(简称CI),CI目前的稳定版本是 3.X,4.0版本已经出来了,但还在测试中,所以我分析的还是 3.x 版本. CI是一个很 ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光.. 由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注 ...
- P值
https://baike.baidu.com/item/P%E5%80%BC/7083622?fr=aladdin https://baijiahao.baidu.com/s?id=15960976 ...
- 使用jQuery发送POST,Ajax请求返回JSON格式数据
问题: 使用jQuery POST提交数据到PHP文件, PHP返回的json_encode后的数组数据,但jQuery接收到的数据不能解析为JSON对象,而是字符串{"code" ...
- POJ 2395 Out of Hay (prim)
题目链接 Description The cows have run out of hay, a horrible event that must be remedied immediately. B ...
- ubuntu设置默认python版本
原文:https://www.cnblogs.com/johnny1024/p/8400511.html ··· ubuntu 16.04本身是自带python的,他本身是自带2.X和3.X,两个版本 ...
- shell脚本复制文件夹内容到另外的文件夹,如果存在则自动备份
有时我们需要将一个文件夹覆盖到我们的工作目录,但需要自动备份已经存在的文件,一个一个去备份太麻烦了,全部备份又没有必要.shell脚本可以很好滴完成这个任务.原文链接http://back.zhizh ...
- 转载:超级强大的vim配置(vimplus)--续集
超级强大的vim配置(vimplus)--续集 原文地址:https://www.cnblogs.com/highway-9/p/5984285.html An automatic configura ...