Nice boat

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

线段树:我是先把每个点标记,然后向上push的时候能合并的合并,然后暴利就过了,算是水过去的。 在学习下别人的。

  1 // by caonima
  2 // hehe
  3 #include <cstdio>
  4 #include <cstring>
  5 #include <vector>
  6 #include <algorithm>
  7 #include <queue>
  8 #include <stack>
  9 #include <string>
 10 #include <iostream>
 11 #include <set>
 12 using namespace std;
 13 const int MAX= 1e5+;
 14 const int inf = 0x3f3f3f3f;
 15 const int MOD = 1e9+;
 16 const double eps= 1e-;
 17 typedef long long LL ;
 18 typedef vector<int> vec;
 19 typedef vector<vec> mat;
 20 
 21 LL gcd(LL a,LL b) {
 22     return b==?a:gcd(b,a%b);
 23 }
 24 
 25 LL ans[MAX<<],col[MAX<<],a[MAX];
 26 
 27 void push_up(int o) {
 28     if(col[o<<]==col[o<<|]) col[o]=col[o<<];
 29 }
 30 void push_down(int o) {
 31     if( [o]!=-) {
 32         col[o<<]=col[o<<|]=col[o];
 33         col[o]=-;
 34     }
 35     return ;
 36 }
 37 void build(int L,int R,int o) {
 38     col[o]=-;
 39     if(L==R) {
 40         col[o]=a[L];
 41         return ;
 42     }
 43     int mid=(L+R)>>;
 44     build(L,mid,o<<);
 45     build(mid+,R,o<<|);
 46     push_up(o);
 47 }
 48 
 49 void modify1(int L,int R,int o,int ls,int rs,LL x) {
 50     if(ls<=L&&rs>=R) {
 51         col[o]=x;
 52         return ;
 53     }
 54     push_down(o);
 55     int mid=(L+R)>>;
 56     if(ls<=mid) modify1(L,mid,o<<,ls,rs,x);
 57     if(rs>mid) modify1(mid+,R,o<<|,ls,rs,x);
 58     push_up(o);
 59 }
 60 void modify2(int L,int R,int o,int ls,int rs,LL x) {
 61     if(ls<=L&&rs>=R&&col[o]!=-) {
 62         if(col[o]>x) {
 63             col[o]=gcd(col[o],x);
 64         }
 65         return ;
 66     }
 67     push_down(o);
 68     int mid=(L+R)>>;
 69     if(ls<=mid) modify2(L,mid,o<<,ls,rs,x);
 70     if(rs>mid) modify2(mid+,R,o<<|,ls,rs,x);
 71     push_up(o);
 72 }
 73 LL Query(int L,int R,int o,int k) {
 74     if(L==R) {
 75         return col[o];
 76     }
 77     push_down(o);
 78     int mid=(L+R)>>;
 79     if(k<=mid) return Query(L,mid,o<<,k);
 80     else return Query(mid+,R,o<<|,k);
 81 }
 82 int main() {
 83     int cas,n,op,ls,rs,m;
 84     LL x;
 85     scanf("%d",&cas);
 86     while(cas--) {
 87         scanf("%d",&n);
 88         for(int i=;i<=n;i++) scanf("%I64d",&a[i]);
 89         build(,n,);
 90         scanf("%d",&m);
 91         for(int i=;i<m;i++) {
 92             scanf("%d %d %d %I64d",&op,&ls,&rs,&x);
 93             if(op==) {
 94                 modify1(,n,,ls,rs,x);
 95             }
 96             else modify2(,n,,ls,rs,x);
 97         }
 98 
 99         for(int i=;i<=n;i++) {
            // if(i==1) printf("%I64d",Query(1,n,1,i));
            printf("%I64d ",Query(,n,,i));
         }
         printf("\n");
         //printf(" ");
     }
     return ;

107 }

HDU 4902 (牛叉的线段树)的更多相关文章

  1. HDU 4902 Nice boat (线段树)

    Nice boat 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4902 Description There is an old country a ...

  2. 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)

    题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...

  3. hdu 4902 Nice boat(线段树区间改动,输出终于序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 Problem Description There is an old country and ...

  4. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  5. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  6. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  7. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

  8. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  9. HDU.1689 Just a Hook (线段树 区间替换 区间总和)

    HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...

随机推荐

  1. Head Html Css 第二版笔记

    一. 引用 <blockquote>ago aog aogag </blockquote> 则是引用一大段文字并独立显示 二. <a> 创建目的地 <h2&g ...

  2. linux Java环境变了配置

    1. sudo /etc/profile 2.安装截图配置 输入javac 进行验证

  3. java Class.getResource和ClassLoader.getResource

    http://www.cnblogs.com/wang-meng/p/5574071.html http://blog.csdn.net/earbao/article/details/50009241 ...

  4. Poj 3694 Network (连通图缩点+LCA+并查集)

    题目链接: Poj 3694 Network 题目描述: 给出一个无向连通图,加入一系列边指定的后,问还剩下多少个桥? 解题思路: 先求出图的双连通分支,然后缩点重新建图,加入一个指定的边后,求出这条 ...

  5. 暴力/思维 HDOJ 5386 Cover

    题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...

  6. LPS HDOJ 4745 Two Rabbits

    题目传送门 /* 题意:一只兔子顺时针跳,另一只逆时针跳,跳石头权值相等而且不能越过起点 LPS:这道就是LPS的应用,把环倍增成链,套一下LPS,然而并不能理解dp[i][i+n-2] + 1,看别 ...

  7. Hibernate 一对多查询对set的排序

    Hibernate可以进行一对多的关联查询,例如:查询了试卷题目,可以自动获取试卷题目的选项对象. 但是关联出来的集合对象是无序的,那么在显示的时候就会有问题,经过百度发现可以对Set进行设置排序. ...

  8. jquery.autocomplete.js用法及示例,小白进

    8 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 ...

  9. 解决Unicode编码(&#29848;)

    随着互联网发展,B/S越来越受欢迎 Code编码格式也越来载多, 在大千花花世界 中文在Web显示看似一样但实际编码并不样,导致从页面获取的资料录入到数据库中时 存取的就是Code编码 如:Unico ...

  10. python--12、索引知识

    MySQL索引及优化 影响性能的因素 需求:一个论坛帖子总量的统计,附加要求:实时更新.从功能上来看非常容易实现,执行一条 SELECT COUNT(*) from 表名 的 Query 就可以得到结 ...