2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)
题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i])。输出最后n个数。
思路 : 暴力线段树,将区间进行更新,可以用延迟标记,也可以不用。p数组代表当前节点这一段上的值是不是相同,不全相同就是-1.
//
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std ; #define LL long long
LL a ,lz[*],p[*]; void pushup(int rt)
{
if(p[rt << ] == p[rt << | ])
p[rt] = p[rt << ] ;
else p[rt] = - ;
} void pushdown(int rt)
{
if(lz[rt] != -)
{
lz[rt << ] = lz[rt << | ] = lz[rt] ;
p[rt << ] = p[rt << | ] = lz[rt] ;
lz[rt] = - ;
}
}
void build(int l,int r,int rt)
{
lz[rt] = - ;
if(l == r)
{
scanf("%I64d",&a) ;
p[rt] = a;
return ;
}
int mid = (l + r) >> ;
build(l,mid,rt << ) ;
build(mid+,r,rt << | ) ;
pushup(rt) ;
} void update(int L,int R,int l,int r,int rt,LL sc,int flag)
{
if(flag > )
{
if(l >= L && r <= R)
{
p[rt] = lz[rt] = sc ;
return ;
}
}
else
{
if(p[rt] != - && (l >= L && r <= R))
{
if(p[rt] > sc)
{
lz[rt] = p[rt] = __gcd(p[rt],sc) ;
}
return ;
}
}
pushdown(rt) ;
int mid = (l+r) >> ;
if(mid >= L)
update(L,R,l,mid,rt << ,sc,flag) ;
if(R > mid)
update(L,R,mid+,r,rt << | ,sc,flag) ;
pushup(rt) ;
} void output(int l ,int r,int rt)
{
if(l == r)
{
printf("%I64d ",p[rt]) ;
return ;
}
pushdown(rt) ;
int mid = (l + r) >> ;
output(l,mid,rt << ) ;
output(mid+,r,rt << | ) ;
}
int main()
{
int T ,n,Q ;
cin >> T ;
while(T--)
{
scanf("%d",&n) ;
build(,n,) ;
scanf("%d",&Q) ;
int t,l,r;
LL x ;
while(Q--)
{
scanf("%d %d %d %I64d",&t,&l,&r,&x) ;
if(t == )
update(l,r,,n,,x,) ;
else
update(l,r,,n,,x,-) ;
}
output(,n,) ;
puts("") ;
}
return ;
}
2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)的更多相关文章
- HDU 4902 Nice boat --线段树(区间更新)
题意:给一个数字序列,第一类操作是将[l,r]内的数全赋为x ,第二类操作是将[l,r]中大于x的数赋为该数与x的gcd,若干操作后输出整个序列. 解法: 本题线段树要维护的最重要的东西就是一个区间内 ...
- HDU 3577 Fast Arrangement (线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...
- hdu 1698+poj 3468 (线段树 区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...
- 2014多校第四场1005 || HDU 4901 The Romantic Hero (DP)
题目链接 题意 :给你一个数列,让你从中挑选一些数组成集合S,挑另外一些数组成集合T,要求是S中的每一个数在原序列中的下标要小于T中每一个数在原序列中下标.S中所有数按位异或后的值要与T中所有的数按位 ...
- hdu 4902 Nice boat 线段树
题目链接 给n个数, 两种操作, 第一种是将区间内的数变成x, 第二种是将区间内大于x的数变为gcd(x, a[i]). 开三个数组, 一个记录区间最大值, 这样可以判断是否更新这一区间, 一个laz ...
- HDU 4902 Nice boat 线段树+离线
据说暴力也过了.还傻逼地写了这么长. . . #include <stdio.h> #include <string.h> #include <math.h> #i ...
- hdu 3397 Sequence operation 线段树 区间更新 区间合并
题意: 5种操作,所有数字都为0或1 0 a b:将[a,b]置0 1 a b:将[a,b]置1 2 a b:[a,b]中的0和1互换 3 a b:查询[a,b]中的1的数量 4 a b:查询[a,b ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- 牛客多校第三场 G Removing Stones(分治+线段树)
牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...
随机推荐
- hdu 2035 人见人爱A^B
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2035 人见人爱A^B Description 求A^B的最后三位数表示的整数.说明:A^B的含义是“A ...
- poj 3625 Building Roads
题目连接 http://poj.org/problem?id=3625 Building Roads Description Farmer John had just acquired several ...
- Android 编译使用高版本的Java
讨论的链接 http://bbs.csdn.net/topics/390977000 问题很容易解决,就是sdk\tools\ant\build.xml里面的配置不对,把 <property n ...
- 如何在Window上使用Git
开始的时候同事只给了一个地址,类似这样:git@111.111.1.1:ABCDEF (1)如何在Windows上使用Git 有一篇博客不错:http://www.tuicool.com/articl ...
- com.ibatis.sqlmap.client.SqlMapException: There is already a statement named search in this SqlMap.
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeExcep ...
- To add private variable to this Javascript literal object
You can use number as function/variable name, the numberic name can't be accessed from parent scope, ...
- DES,3DES,AES这三种对称密钥的区别与联系
DES:Data Encryption Standard(数据加密标准,又美国国密局,选中的IBM的方案,密钥长度为56,标准提出是要使用64位长的密钥,但是实际中DES算法只用了64位中的56位密钥 ...
- 基于.net mvc的校友录(三、实体模型实现)
实体模型设计 由于是实际开发,而且是时间比较紧的,所以,在开发实现过程中,总有一些对原计划的改动: AlumniBookModel数据库实体模型 这是主数据实体类,EF会根据此实体生成数据库,它的每一 ...
- Shell常用操作
1.读取配置文件中的jdbc_url参数的值($InputParamFile为待读取的目标文件绝对路径) jdbc_url=`grep "jdbc_url" $InputParam ...
- Google Guava学习笔记——基础工具类Preconditions类的使用
Preconditions类是一组静态方法用来验证我们代码的状态.Preconditons类很重要,它能保证我们的代码按照我们期望的执行,如果不是我们期望的,我们会立即得到反馈是哪里出来问题,现在我们 ...