题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902

Problem Description
There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.

Let us continue our story, z*p(actually you) defeat the 'MengMengDa' party's leader, and the 'MengMengDa' party dissolved. z*p becomes the most famous guy among the princess's knight party.

One day, the people in the party find that z*p has died. As what he has done in the past, people just say 'Oh, what a nice boat' and don't care about why he died.

Since then, many people died but no one knows why and everyone is fine about that. Meanwhile, the devil sends her knight to challenge you with Algorithm contest.

There is a hard data structure problem in the contest:

There are n numbers a_1,a_2,...,a_n on a line, everytime you can change every number in a segment [l,r] into a number x(type 1), or change every number a_i in a segment [l,r] which is bigger than x to gcd(a_i,x) (type 2).

You should output the final sequence.

Input
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains a integers n.
The next line contains n integers a_1,a_2,...,a_n separated by a single space.
The next line contains an integer Q, denoting the number of the operations.
The next Q line contains 4 integers t,l,r,x. t denotes the operation type.

T<=2,n,Q<=100000
a_i,x >=0
a_i,x is in the range of int32(C++)

Output
For each test case, output a line with n integers separated by a single space representing the final sequence.
Please output a single more space after end of the sequence
Sample Input
1 10 16807 282475249 1622650073 984943658 1144108930 470211272 101027544 1457850878 1458777923 2007237709 10 1 3 6 74243042 2 4 8 16531729 1 3 4 1474833169 2 1 8 1131570933 2 7 9 1505795335 2 3 7 101929267 1 4 10 1624379149 2 2 8 2110010672 2 6 7 156091745 1 2 5 937186357
Sample Output
16807 937186357 937186357 937186357 937186357 1 1 1624379149 1624379149 1624379149
Author
WJMZBMR
Source
2014 Multi-University Training Contest 4 
题目意思:
给出长度为n的数组,m个操作。操作有两种:1、1, l, r, x即把[l,r]段的元素全变为x。2、2,l,r,x即把[l,r]段的大于x的元素全变成该元素与x的最大公约数。

代码例如以下:

#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define LL long long
const int maxn = 111111;
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define lson l, mid, ls
#define rson mid+1, r, rs
//num数组表示该区间是否都是同一个数,假设是num就等于这个数,否则等-1
int num[maxn << 2];
//flag标记,表示该区间是否应该被纯色化(变成一个数)。
int flag[maxn << 2];
//mmax数组表示该区间的最大值,由于gcd仅仅对该区间比x大的起作用
int mmax[maxn << 2];
int GCD(int a, int b)
{return a ?

GCD(b%a,a) : b; } void Pushup(int rt) { if(num[ls] == num[rs]) num[rt] = num[ls]; else num[rt] = -1; mmax[rt] = max(mmax[ls], mmax[rs]); } void Pushdown(int rt) { if(flag[rt] != -1) { flag[ls] = flag[rs] = flag[rt]; mmax[ls] = mmax[rs] = mmax[rt]; num[ls] = num[rs] = num[rt]; flag[rt] = -1; } } void build(int l, int r, int rt) { flag[rt] = -1; if(l == r) { scanf("%d",&num[rt]); mmax[rt] = num[rt];//初始化 return ; } int mid = (l+r) >> 1; build(lson); build(rson); Pushup(rt); } void update(int L, int R, int x, int l, int r, int rt) { if(L <= l && r <= R) { flag[rt] = num[rt] = mmax[rt] = x; return ; } Pushdown(rt); int mid = (l+r) >> 1; if(L <= mid) update(L, R, x, lson); if(mid < R) update(L, R, x, rson); Pushup(rt); } void modify(int L, int R, int x, int l, int r, int rt) { if(L <= l && r <= R && num[rt] > x) { flag[rt] = num[rt] = mmax[rt] = GCD(num[rt], x); return ; } Pushdown(rt); int mid = (l+r) >> 1; if(L <= mid && mmax[ls] > x) modify(L, R, x, lson); if(mid < R && mmax[rs] > x) modify(L, R, x, rson); Pushup(rt); } void Cout(int l, int r, int rt) { if(l == r) { printf("%d ",num[rt]); return ; } Pushdown(rt); int mid = (l+r) >> 1; Cout(lson); Cout(rson); } int main() { int T; int R, L; int n, m; int op,l, r, x; int i, j, k; scanf("%d",&T); while(T--) { scanf("%d",&n); build(1,n,1); scanf("%d",&m); for(i = 0; i < m; i++) { scanf("%d%d%d%d",&op,&l,&r,&x); if(op == 1) { update(l, r, x, 1, n, 1); } else if(op == 2) { modify(l, r, x, 1, n, 1); } } Cout(1, n, 1); printf("\n"); } return 0; }

转载于:https://www.cnblogs.com/lxjshuju/p/6830818.html

hdu 4902 Nice boat(线段树区间改动,输出终于序列)相关推荐

  1. HDU - 4902 Nice boat(线段树)

    题目链接:点击查看 题目大意:给出 n 个数字组成的数列 a ,需要进行 m 次操作,每次操作分为以下两种: 1 l r val:将区间 [ l , r ] 内的 a[ i ] 都赋值为 val 2 ...

  2. HDU 1540 Tunnel Warfare 线段树区间合并

    Tunnel Warfare 题意:D代表破坏村庄,R代表修复最后被破坏的那个村庄,Q代表询问包括x在内的最大连续区间是多少 思路:一个节点的最大连续区间由(左儿子的最大的连续区间,右儿子的最大连续区 ...

  3. HDU - 3397 Sequence operation(线段树+区间合并)

    题目链接:点击查看 题目大意:给定一个初始的数列,然后依次进行m次操作: 0 a b:将闭区间[a,b]内的点都变为0 1 a b:将闭区间[a,b]内的点都变为1 2 a b:将闭区间[a,b]内的 ...

  4. HDU - 2871 Memory Control(线段树+区间合并)好题!

    题目链接:点击查看 题目大意:给定n个内存和m个操作,分别是: New x:从内存编号1开始向右查找,分配一个长度为x的空间,若找到输出区间的首地址,否则输出Reject New: Free x:释放 ...

  5. HDU - 1540 Tunnel Warfare(线段树+区间合并)

    题目链接:点击查看 题目大意:给定n个村庄,初始化全部连接为一条直线,需要依次执行m个操作,D表示摧毁第i个村庄的连接,R表示恢复最后一 个被摧毁的村庄的连接,Q表示询问包括本身在内,与第i个村庄相连 ...

  6. HDU - 3333 Turing Tree 线段树区间不同值和+详解+思想

    传送门 首先第一次做这种求不同元素和的线段树题,猜想是个裸题.但是题目中有一句话显然给题目降低了很大的难度,就是 想想其实它就是在暗示你这道题你要结合多次询问来处理,也就是所谓的离线,而不是一次一次的 ...

  7. hdu 1540 Tunnel Warfare(线段树区间合并)

    hdu 1540 Tunnel Warfare 记录每个节点的最大左连续值.最大右连续值.最大连续值,向上更新的是常规的区间合并处理方式 关键是想到如何去查询,如果查询节点落在左儿子节点的右连续段中, ...

  8. hdu 5692 Snacks(dfs序+线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5692 解题思路:这道题是树节点的点权更新,而且涉及到子树,常用的思路是利用dfs序,用线段树来对区间进 ...

  9. hdu 3966(树链剖分+线段树区间更新)

    传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...

最新文章

  1. 企业安全挑战 内网安全技术十大策略
  2. 优秀logo设计解析_优秀Logo设计!汽车类标志表现手法
  3. java升级为jdk1.8_jdk1.7升级为1.8
  4. 【干货】史上最全的Tensorflow学习资源汇总
  5. html笔记(二)html4+css2.0(元素类型、css精灵、宽度自适应、BFC、浏览器相关概述、css统筹)
  6. expdp导出 schema_记录一则expdp任务异常处理案例
  7. python导入math函数取一随机数返回其平方根_Python数字
  8. java生成pdf的流_Java 文件输出流.pdf
  9. java x86 x64_jdk x86与jdk x64 有什么区别
  10. 使用最新TexLive2020+VsCode来编写Latex论文(假设使用:CVPR2018)
  11. 在线pdf转epub网站
  12. python 根据word生成ppt_python操作word、ppt的详解
  13. Unity Pico老版SDK手柄功能编写
  14. 第一批用基因编辑工具定制DNA的婴儿即将诞生?
  15. 【收藏】清风算法后网站首页/列表页/内容页/主题聚合页标题格式
  16. CSS精灵图、字体图标
  17. Fedora/CentOS安装Komorebi动态壁纸
  18. cmd命令下,使用java命令,运行指定目录下的*.class文件。
  19. Win7系统下安装Python环境以及IDE开发环境(PyCharm)
  20. 微信公众号下载神器—WeChatDownload

热门文章

  1. 分布式数据库中间件 MyCat 搞起来
  2. c语言基础课第二次作业
  3. sklearn.covariance(协方差)模块结构及用法
  4. xml中[CDATA[]]浅解
  5. 【单片机笔记】基于STM32硬件平台的最新FATFS 最新版ff14版本的移植
  6. java neo4j_Neo4j基本入门
  7. Python对视频进行分帧保存图片
  8. 机器学习——线性判别分析
  9. 小型项目——扫雷游戏(模块化实现)
  10. Python执行selenium报错This version of ChromeDriver only supports Chrome version并配置环境变量