题目链接

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. [福利]可持久化线段树的更多相关文章

  1. AC日记——[福利]可持久化线段树 cogs 2554

    2554. [福利]可持久化线段树 ★★☆   输入文件:longterm_segtree.in   输出文件:longterm_segtree.out   简单对比时间限制:3 s   内存限制:2 ...

  2. cogs2554 [福利]可持久化线段树

    cogs2554 [福利]可持久化线段树 原题链接 每次修改复制一遍就行了... 1A!!! // It is made by XZZ #include<cstdio> #include& ...

  3. YSZOJ:#247. [福利]可持久化线段树 (最适合可持久化线段树入门)

    题目链接:https://syzoj.com/problem/247 解题心得: 可持久化线段树其实就是一个线段树功能的加强版,加强在哪里呢?那就是如果一颗普通的线段树多次修改之后还能知道最开始的线段 ...

  4. [COGS2554][SYZOJ247][福利]可持久化线段树

    思路: 主席树模板. 注意内存的分配,原始的线段树有$2n$个结点,每次更新时最多增加$log(n)$个结点,总共有$q$次询问,所以存储结点的数组大小为$2N+q log(n)$. #include ...

  5. PYOJ 44. 【HNSDFZ2016 #6】可持久化线段树

    #44. [HNSDFZ2016 #6]可持久化线段树 统计 描述 提交 自定义测试 题目描述 现有一序列 AA.您需要写一棵可持久化线段树,以实现如下操作: A v p x:对于版本v的序列,给 A ...

  6. 【BZOJ-3673&3674】可持久化并查集 可持久化线段树 + 并查集

    3673: 可持久化并查集 by zky Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 1878  Solved: 846[Submit][Status ...

  7. 【BZOJ-2653】middle 可持久化线段树 + 二分

    2653: middle Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1298  Solved: 734[Submit][Status][Discu ...

  8. HDU 4866 Shooting(持久化线段树)

    view code//第二道持久化线段树,照着别人的代码慢慢敲,还是有点不理解 #include <iostream> #include <cstdio> #include & ...

  9. 【BZOJ-3653】谈笑风生 DFS序 + 可持久化线段树

    3653: 谈笑风生 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 628  Solved: 245[Submit][Status][Discuss] ...

随机推荐

  1. 统计无符号整数二进制中1的个数(Hamming weight)

    1.问题来源 之所以来记录这个问题的解法,是因为在在线编程中经常遇到,比如编程之美和京东的校招笔试以及很多其他公司都累此不疲的出这个考题.看似简单的问题,背后却隐藏着很多精妙的解法.查找网上资料,才知 ...

  2. Dubbo入门介绍---搭建一个最简单的Demo框架

    Dubbo入门---搭建一个最简单的Demo框架 置顶 2017年04月17日 19:10:44 是Guava不是瓜娃 阅读数:320947 标签: dubbozookeeper 更多 个人分类: D ...

  3. Spring源码解析-事件

    Spring事件的组件 主要是3个组件: 1.ApplicationEvent   事件 2.ApplicationListener 监听器,对事件进行监听 3.ApplicationEventMul ...

  4. Qt 设置应用程序图标(windows)

    Step 1: 创建  xxx.rc 文件. 将ico图标文件复制到项目根目录下.然后在该目录中新建xxx.rc文件,并输入一行代码: IDI_ICON1 ICON DISCARDABLE " ...

  5. 7月20号day12总结

    今天学习过程和小结 先进行了复习,主要 1,hive导入数据的方式有 本地导入  load data [local] inpath 'hdfs-dir' into table tablename; s ...

  6. 修改firefox默认下载路径

    菜单栏---编辑---首选项--在常规页就可以看到下载设置了

  7. SpringMVC学习 -- ModelAndView , Model , ModelMap , Map 及 @SessionAttributes 的使用

    输出模型数据: ModelAndView:处理方法返回值类型为 ModelAndView 时 , 其中包含视图和模型信息.方法体即可通过该对象添加模型数据 , 即 SpringMVC 会把 Model ...

  8. JS遮罩层弹框效果

    对于前端开发者来说,js是不可缺少的语言.现在我开始把我日常积累的一些js效果或者通过搜索自己总结的一些效果分享给大家,希望能够帮助大家一起进步,也希望大家能够多多支持! 1.今天我先分享一个遮罩层弹 ...

  9. 【uva11732-"strcmp()" Anyone?】Trie

    http://acm.hust.edu.cn/vjudge/problem/28438 题意:给定n个字符串,问用strcmp函数比较这些字符串共用多少次比较. 题解: 插入一个‘#’作为字符串的结束 ...

  10. 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

    [题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...