hdu--4902--线段树
题意 前面一段废话= =
这题 最有意思的应该是出题人 是clj
这题的时限放的太宽了 给了15s 我也是醉了
区间更新。
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 const int size = 200010; 6 int a[size]; 7 struct data 8 { 9 int L , R , maxVar; 10 bool flag; 11 }tree[size<<2]; 12 13 int gcd( int x , int y ) 14 { 15 return x % y == 0 ? y : gcd( y , x%y ); 16 } 17 18 void pushDown( int rt ) 19 { 20 tree[rt<<1].maxVar = tree[rt<<1|1].maxVar = tree[rt].maxVar; 21 tree[rt<<1].flag = tree[rt<<1|1].flag = true; 22 tree[rt].flag = false; 23 } 24 25 void pushUp( int rt ) 26 { 27 tree[rt].maxVar = max( tree[rt<<1].maxVar , tree[rt<<1|1].maxVar ); 28 } 29 30 void build( int rt , int L , int R ) 31 { 32 int M = ( L + R ) >> 1; 33 tree[rt].L = L , tree[rt].R = R; 34 tree[rt].flag = false; 35 if( L==R ) 36 { 37 tree[rt].maxVar = a[L]; 38 tree[rt].flag = true; 39 return ; 40 } 41 build( rt<<1 , L , M ); 42 build( rt<<1|1 , M+1 , R ); 43 pushUp( rt ); 44 } 45 46 void update( int rt , int L , int R , int x , int op ) 47 { 48 int M = ( tree[rt].L + tree[rt].R ) >> 1; 49 if( tree[rt].L == L && tree[rt].R == R ) 50 { 51 if( op==1 ) 52 { 53 tree[rt].maxVar = x; 54 tree[rt].flag = true; 55 return; 56 } 57 else 58 { 59 if( tree[rt].maxVar<=x ) 60 return ; 61 if( tree[rt].flag && tree[rt].maxVar>x ) 62 { 63 tree[rt].maxVar = gcd( tree[rt].maxVar , x ); 64 return; 65 } 66 } 67 } 68 if( tree[rt].flag ) 69 { 70 pushDown( rt ); 71 } 72 if( R<=M ) 73 { 74 update( rt<<1 , L , R , x , op ); 75 } 76 else if( L>=M+1 ) 77 { 78 update( rt<<1|1 , L , R , x , op ); 79 } 80 else 81 { 82 update( rt<<1 , L , M , x , op ); 83 update( rt<<1|1 , M+1 , R , x , op ); 84 } 85 pushUp( rt ); 86 } 87 88 void solve( int rt , int L , int R ) 89 { 90 int M = ( tree[rt].L + tree[rt].R ) >> 1; 91 if( L == R ) 92 { 93 cout << tree[rt].maxVar << " "; 94 return ; 95 } 96 if( tree[rt].flag ) 97 { 98 pushDown( rt ); 99 } 100 solve( rt<<1 , L , M ); 101 solve( rt<<1|1 , M+1 , R ); 102 } 103 104 int main() 105 { 106 cin.sync_with_stdio(false); 107 int t , n , m , op , L , R , x; 108 cin >> t; 109 while( t-- ) 110 { 111 cin >> n; 112 for( int i = 1 ; i<=n ; i++ ) 113 cin >> a[i]; 114 build( 1 , 1 , n ); 115 cin >> m; 116 while( m-- ) 117 { 118 cin >> op >> L >> R >> x; 119 update( 1 , L , R , x , op ); 120 } 121 solve( 1 , 1 , n ); 122 cout << endl; 123 } 124 return 0; 125 }
View Code
明天 是个特殊的日子 。。
转载于:https://www.cnblogs.com/radical/p/4162103.html
hdu--4902--线段树相关推荐
- POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新
直接将这3题 放一起了 今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...
- hdu 5367(线段树+区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5367 官方题解: 对于求"高山脉"长度,可以利用线段树.树节点中保存左高度连续长度 ...
- hdu 5266(线段树+LCA)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5266 解题思路: 考虑dfs序,通过在简单的证明可知L~R的LCA为L ~R 中dfs序较小的那个位置 ...
- hdu 5124(线段树区间更新+lazy思想)
http://acm.hdu.edu.cn/showproblem.php?pid=5124 题意:区间覆盖次数问题. 解题思路:线段树水之. #include<iostream> #in ...
- HDU - 4578Transformation——线段树+区间加法修改+区间乘法修改+区间置数+区间和查询+区间平方和查询+区间立方和查询
[题目描述] HDU - 4578Transformation Problem Description Yuanfang is puzzled with the question below: The ...
- poj 2777 AND hdu 5316 线段树
区间染色问题,用线段树可以解决.颜色总类不多,故考虑用二进制数的每一位表示一种颜色,然后父节点的颜色就是孩子节点颜色"或"起来,加上lazy标记,轻松AC. poj 2777: 1 ...
- HDU 5238 线段树+数论
原题:http://acm.hdu.edu.cn/showproblem.php?pid=5238. 题解:给你长度为n的操作序列,和m组操作求每组操作的模29393的值.这道题直接显然是没有前途的, ...
- poj 2528 离散化+线段树 hdu 1698 线段树 线段树题目类型一:染色计数 外加离散化
第一次听到离散化是今年省赛的时候,一道矩形并的题,很水,就两个矩形... 今天再去做线段树已经发现离散化忘得差不多了...水逼的悲哀啊... 先看简单点的hdu 1698 http://acm.hdu ...
- HDU 1166(线段树)
线段树 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 #define N 200010 ...
- hdu 4417(线段树OR树状数组)
题意:输入一个长度为n的序列,然后m个询问,询问区间[a,b]中比h小的数的个数. 思路:树状数组或线段树离线处理. 树状数组1 View Code 1 #include<cstdio> ...
最新文章
- LoadRunner做性能测试 从设计到分析执行
- Android Jetpack组件之 Paging使用-源码
- NA-NP-IE系列实验28:HDLC 和PPP 封装
- 服务器宕机不再愁!Docker 内置功能帮您解决
- (转)Spring Boot 2 (三):Spring Boot 开源软件都有哪些?
- hexo -d 部署的时候报错 FATAL Something's wrong Template render error: expected variable
- Notepad++配置Python运行环境
- 文化的作用与本质是什么
- java中native的详解
- 选择排序是外面循环的array[i]与内循环的array[j]比较。冒泡排序是内循环的相邻两个值做比较修改...
- Code First 约定
- View Horizon Mirage安装手册(三)——Mirage Management安装
- PRML第三章3.3贝叶斯线性回归
- 人体存在感应雷达技术,车内生命体征检测,毫米波雷达探测模块
- 3DMM(人脸3D形变统计模型)
- C4D R18-R21
- 高校大数据产品有哪些
- linux 中cat用法
- UG NX 12同步建模:调整面大小
- 关于词嵌入(Word Embedding)的一些总结
热门文章
- POJ 1521 Entropy
- 【JOURNAL】好久了啊
- 多线程多进程解析:Python、os、sys、Queue、multiprocessing、threading
- 怎样正确使用和维护微型计算机,下篇:微型计算机应该怎样进行维护与保养
- haproxy配置代理tomcat和nginx_你真的掌握LVS、Nginx及HAProxy工作原理吗?
- vue项目中使用mock(一)
- 产品经理思维模型:新的增长黑客模型RARRA
- 七点人脸姿态估计_Github开源库简单配置即可上线的3D人脸检测工具箱
- yum安装odbc驱动linux,在CentOS上离线配置PostgreSQL ODBC数据源
- java枚举怎么编译不行的_java枚举类型