【HDOJ】4902 Nice boat
区间线段树。题目还不错。
/* */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std; #define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define MAXN 100005 typedef struct {
int mx, val;
} node_t; node_t T[MAXN<<];
int n, m, x;
int l; int gcd(int n, int m) {
if (m == )
return n;
if (m > n)
return gcd(m, n);
return gcd(m, n%m);
} void PushUp(int rt) {
T[rt].val = T[rt<<].val==T[rt<<|].val ? T[rt<<].val:-;
T[rt].mx = max(T[rt<<].mx, T[rt<<|].mx);
} void PushDown(int rt) {
if (T[rt].val >= ) {
T[rt<<].val = T[rt<<|].val = T[rt].val;
T[rt<<].mx = T[rt<<|].mx = T[rt].mx;
}
} void build(int l, int r, int rt) {
if (l == r) {
scanf("%d", &T[rt].val);
T[rt].mx = T[rt].val;
return ;
}
int mid = (l+r)>>;
build(lson);
build(rson);
PushUp(rt);
} void update1(int ll, int rr, int l, int r, int rt) {
if (ll<=l && rr>=r) {
T[rt].val = x;
T[rt].mx = x;
return ;
}
int mid = (l+r)>>;
PushDown(rt);
if (rr <= mid) {
update1(ll, rr, lson);
} else if (ll > mid) {
update1(ll, rr, rson);
} else {
update1(ll, mid, lson);
update1(mid+, rr, rson);
}
PushUp(rt);
} void update2(int ll, int rr, int l, int r, int rt) {
if (T[rt].mx <= x)
return ;
int mid = (l+r)>>;
if (ll<=l && rr>=r) {
if (T[rt].val >= ) {
T[rt].val = gcd(T[rt].val, x);
T[rt].mx = T[rt].val;
} else {
update2(ll, rr, lson);
update2(ll, rr, rson);
PushUp(rt);
}
return ;
}
PushDown(rt);
if (rr <= mid) {
update2(ll, rr, lson);
} else if (ll > mid) {
update2(ll, rr, rson);
} else {
update2(ll, mid, lson);
update2(mid+, rr, rson);
}
PushUp(rt);
} void printAll(int l, int r, int rt) {
if (T[rt].val >= ) {
for (int i=l; i<=r; ++i)
printf("%d ", T[rt].val);
return ;
}
int mid = (l+r)>>;
printAll(lson);
printAll(rson);
} int main() {
int i, j, k;
int l, r;
int t; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
scanf("%d", &n);
build(, n, );
scanf("%d", &m);
while (m--) {
scanf("%d %d %d %d", &k, &l, &r, &x);
if (k == ) {
update1(l, r, , n, );
} else {
update2(l, r, , n, );
}
}
printAll(, n, );
putchar('\n');
} return ;
}
【HDOJ】4902 Nice boat的更多相关文章
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
- 【HDOJ】【1512】Monkey King
数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...
随机推荐
- Android canvas rotate():平移旋转坐标系至任意原点任意角度-------附:android反三角函数小结
自然状态下,坐标系以屏幕左上角为原点,向右是x正轴,向下是y正轴.现在要使坐标系的原点平移至任一点O(x,y),且旋转a角度,如何实现? 交待下我的问题背景,已知屏幕上有两点p1和p2,构成直线l.我 ...
- PHP能得到你是从什么页面过来的,r…
在开发web程序的时候,有时我们需要得到用户是从什么页面连过来的,这就用到了referer. 它是http协议,所以任何能开发web程序的语言都可以实现,比如jsp中是: request.getHea ...
- 使用html5兼容低版本浏览器
因为html5 新出的一些语义化的标签,在低版本浏览器下不能识别,举个例子,比如你写了一个 header 标签中,写了一段文本,在低版本浏览器下,肯定是能看到的,但是,那是他是不认识 header标签 ...
- Beyond Compare 设置打开文件的默认编码
转载:http://www.note4u.info/archives/360 Beyond Compare 每次打开都会以西欧(windows)打开文件,在有中文的地方,经常出现乱码.但是设置每个文件 ...
- xp和win 2003远程桌面强制进入命令
xp和win 2003远程桌面强制进入命令 注意:端口号也可以不写 如果是在win 2003里面进行踢人的话可以用命令: mstsc /console /v:172.25.100.27:3389 如果 ...
- IOS-UIScrollView实现图片分页
1.设置可以分页 _scrollView.pagingEnabled = YES; 2.添加PageControl UIPageControl *pageControl = [[UIPageContr ...
- iOS-UI控件精讲之UIView
道虽迩,不行不至:事虽小,不为不成. 相关阅读 1.iOS-UI控件精讲之UIView(本文) 2.iOS-UI控件精讲之UILabel ...待续 UIView是所有UI控件的基类,在布局的时候通常 ...
- 在Windows下用MingW 4.5.2编译OpenCV 2.3.0
需要的工具:1.安装QT SDK环境2.安装CMake for Windows3.OpenCV最新Windows源码步骤:1.将QT SDK安装目录下的{QtSDK}\mingw\bin添加到系统环境 ...
- Jquery效果之固定不动的块
好多页面都有用到这种效果,大概就是不论页面上下如何滚动,固定不动的元素不随页面滚动,代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- ES6-个人学习笔记一--let和const
es6已经推出一段时间了,虽然在兼容和应用上还有不少的难题,但是其提供的未来前端代码编程的发展趋势和一些好用的功能还是很吸引人的,因此个人买了'阮一峰'先生的es6入门,希望对其有一个了解和学习,本系 ...