题目链接

题意 : 给你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 (线段树 区间更新)的更多相关文章

  1. HDU 4902 Nice boat --线段树(区间更新)

    题意:给一个数字序列,第一类操作是将[l,r]内的数全赋为x ,第二类操作是将[l,r]中大于x的数赋为该数与x的gcd,若干操作后输出整个序列. 解法: 本题线段树要维护的最重要的东西就是一个区间内 ...

  2. HDU 3577 Fast Arrangement (线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...

  3. hdu 1698+poj 3468 (线段树 区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...

  4. 2014多校第四场1005 || HDU 4901 The Romantic Hero (DP)

    题目链接 题意 :给你一个数列,让你从中挑选一些数组成集合S,挑另外一些数组成集合T,要求是S中的每一个数在原序列中的下标要小于T中每一个数在原序列中下标.S中所有数按位异或后的值要与T中所有的数按位 ...

  5. hdu 4902 Nice boat 线段树

    题目链接 给n个数, 两种操作, 第一种是将区间内的数变成x, 第二种是将区间内大于x的数变为gcd(x, a[i]). 开三个数组, 一个记录区间最大值, 这样可以判断是否更新这一区间, 一个laz ...

  6. HDU 4902 Nice boat 线段树+离线

    据说暴力也过了.还傻逼地写了这么长. . . #include <stdio.h> #include <string.h> #include <math.h> #i ...

  7. 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 ...

  8. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  9. 牛客多校第三场 G Removing Stones(分治+线段树)

    牛客多校第三场 G Removing Stones(分治+线段树) 题意: 给你n个数,问你有多少个长度不小于2的连续子序列,使得其中最大元素不大于所有元素和的一半 题解: 分治+线段树 线段树维护最 ...

随机推荐

  1. 三种嵌入式web服务器(Boa / lighttpd / shttpd)的 linux移植笔记

    一:移植Boa(web服务器)到嵌入式Linux系统 一.Boa程序的移植 1.下载Boa源码    下载地址: http://www.boa.org/    目前最新发行版本: 0.94.13   ...

  2. 【EF Code First】Migrations数据库迁移

    1,打开工具->NuGet程序管理器->程序包管理器控制台 默认项目中要选择  数据访问上下文类  所在的项目 我的DB是在命名空间CodeFirst.UI下的所以选择CodeFirst. ...

  3. 戏说PHP的嵌套函数

    PHP很早就支持嵌套函数了.并是不PHP5.3有闭包时才有的.然而,它却不是象JS,AS那样的闭包嵌套.即它的嵌套函数根本无闭包模式的逃脱. PHP嵌套函数有一些特别之处.最特别的是,当外部函数被调用 ...

  4. 【每日scrum】NO.2

    1.今天找到了铁大电子地图. 2.需求分析未完成,进度有点慢.

  5. canvas实现跟随鼠标旋转的箭头

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...

  6. canvas画时钟

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  7. android 开发-设置控件/view的水平方向翻转

    设置控件沿着水平方向翻转(即Y轴180°) 看效果: 代码: <pl.droidsonroids.gif.GifImageView android:id="@+id/gv_image1 ...

  8. python 单元测试-unittest

    参考资料:https://docs.python.org/3.4/library/unittest.html#module-unittest 一张图解决问题: 涉及5块内容:case.suite.lo ...

  9. 二分---LIGHTOJ 1062

    1062 - Crossed Ladders PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB A ...

  10. VS2012配置Lua环境

    1.VS2012配置BabeLua插件 2.VS2012配置Lua 1.VS2012配置BabeLua插件 BabeLua插件简介: 安装方法: 关闭VS2012后直接安装BabeLua插件. 下载地 ...