HDU 4902 Nice boat 成段线段树
操作1 的时候标记deng[rt]表示以下一段数都是与当前节点的值同样
下次操作2时直接对有deng标记的节点gcd更新
(可能还能够更简单)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN 11111
#include <queue>
#include <vector>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid (r+l)>>1
const int maxn=100010;
int sum[maxn<<2] ,col[maxn<<2],deng[maxn<<2];
int gcd(int a,int b)
{
while(1)
{
if(b==0)
return a;
int t=b;
b=a%b;
a=t;
}
}
void pushup(int rt)
{
sum[rt]=max(sum[rt<<1],sum[rt<<1|1]);
}
void pushdown(int rt){
if(col[rt])
{
col[rt<<1]=col[rt<<1|1]=col[rt];
sum[rt<<1]=sum[rt<<1|1]=sum[rt];
col[rt]=0;
}
if(deng[rt])
{
deng[rt<<1]=deng[rt<<1|1]=deng[rt];
sum[rt<<1]=sum[rt<<1|1]=sum[rt];
deng[rt]=0;
}
}
void build(int l,int r,int rt)
{
col[rt]=deng[rt]=0;
if(r==l)
{
scanf("%d",&sum[rt]);
return;
}
int m=mid;
build(lson);
build(rson);
pushup(rt);
}
void out(int l,int r,int rt)
{
if(r==l)
{
printf("%d ",sum[rt]);
return;
}
pushdown(rt);
int m=mid;
out(lson);
out(rson);
}
void update1(int L,int R,int num,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[rt]=1;
deng[rt]=1;
sum[rt]=num;
return ;
}
pushdown(rt);
int m=mid;
if(L<=m) update1(L,R,num,lson);
if(m<R) update1(L,R,num,rson);
pushup(rt);
}
void update2(int L,int R,int num,int l,int r,int rt)
{
if(sum[rt]<num)
return ;
if(deng[rt]&&L<=l&&r<=R)
{
sum[rt]=gcd(sum[rt],num);
col[rt]=1;
deng[rt]=0;
return ;
}
if(l==r)
{
sum[rt]=gcd(sum[rt],num);
return ;
}
pushdown(rt);
int m=mid;
if(L<=m) update2(L,R,num,lson);
if(m<R) update2(L,R,num,rson);
pushup(rt);
}
int main()
{
int t,n,q;
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
build(1,n,1);
scanf("%d",&q);
int op,l,r,x;
for(int i=0;i<q;i++)
{
scanf("%d%d%d%d",&op,&l,&r,&x);
if(op==1)
update1(l,r,x,1,n,1);
else
update2(l,r,x,1,n,1);
}
out(1,n,1);
printf("\n");
}
return 0;
}
HDU 4902 Nice boat 成段线段树的更多相关文章
- HDU 4902 (牛叉的线段树)
Nice boat Problem Description There is an old country and the king fell in love with a devil. The de ...
- hdu 5274 Dylans loves tree(LCA + 线段树)
Dylans loves tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)
HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意: 给一个序列由 ...
- HDU 4902 Nice boat (线段树)
Nice boat 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4902 Description There is an old country a ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- hdu 1698 Just a Hook(线段树之 成段更新)
Just a Hook Time Limit: ...
- 线段树 + 区间更新 ----- HDU 4902 : Nice boat
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- HDU 4902 Nice boat --线段树(区间更新)
题意:给一个数字序列,第一类操作是将[l,r]内的数全赋为x ,第二类操作是将[l,r]中大于x的数赋为该数与x的gcd,若干操作后输出整个序列. 解法: 本题线段树要维护的最重要的东西就是一个区间内 ...
随机推荐
- 【原】不定义Order属性,通过切面类的定义顺序来决定通知执行的先后顺序
[结论] 在多个切面类的“切入点相同”并且每个切面都“没有定义order属性”的情况下,则切面类(中的通知)的执行顺序与该切面类在<aop:config>元素中“声明的顺序”相关,即先声明 ...
- Struts2 JSONObject的使用
一.jar包 使用之前必须引入所须要的jar包,这里包含Struts2和JSONObject各自所必须的 Struts2: commons-fileupload-1.2.1.jarcommons-io ...
- How to edit the init.rc in android
We have to perform the following steps to edit your init.rc successfully: . Download the BOOT (R ...
- IP地址便捷修改器 V3.5 绿色版
IP地址便捷修改器 V3.5 绿色版 http://www.downxia.com/downinfo/47786.html#softdown
- 通过使用第三方开源jar包sigar.jar我们可以获得本地的信息
1.下载sigar.jar sigar官方主页 sigar-1.6.4.zip 2.按照主页上的说明解压包后将相应的文件copy到java路径.比如windows32位操作系统需要将lib中sigar ...
- Android图片加载框架最全解析(五),Glide强大的图片变换功能
大家好,又到了学习Glide的时间了.前段时间由于项目开发紧张,再加上后来又生病了,所以停更了一个月,不过现在终于又可以恢复正常更新了.今天是这个系列的第五篇文章,在前面四篇文章的当中,我们已经学习了 ...
- tornado基础入门(一)——简单了解tornado
参考:http://demo.pythoner.com/itt2zh/ch1.html tornado是一个轻量级的web框架,是一个用python写的web服务器,它有三个最大的特点(优势)速度.简 ...
- Python for everyone chapter 1
Chapter 1 10 试题 1. When Python is running in the interactive mode and displaying the chevron prompt ...
- ActiveMQ使用示例之Queue
我们使用ActiveMQ为大家实现一种点对点的消息模型. 开发时候,要将apache-activemq-5.12.0-bin.zip解压缩后里面的activemq-all-5.12.0.jar包加入到 ...
- OpenCV 脸部跟踪(2)
前面一篇文章中提到,我们在一副脸部图像上选取76个特征点,以及这些特征点的连通性信息来描述脸部形状特征,本文中我们会把这些特征点映射到一个标准形状模型. 通常,脸部形状特征点能 ...