每个点最多被修改$O(\log n)$次,线段树记录区间最值暴力更新。

#include<cstdio>
#define N 262145
int T,n,m,i,op,c,d,p,s[N],v[N],tag[N];
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline void up(int x){v[x]=v[x<<1]>v[x<<1|1]?v[x<<1]:v[x<<1|1];tag[x]=tag[x<<1]==tag[x<<1|1]?tag[x<<1]:-1;}
inline void pb(int x){if(~tag[x])tag[x<<1]=tag[x<<1|1]=v[x<<1]=v[x<<1|1]=tag[x];}
void build(int x,int a,int b){
if(a==b){tag[x]=v[x]=s[a];return;}
int mid=(a+b)>>1;
build(x<<1,a,mid),build(x<<1|1,mid+1,b),up(x);
}
void change1(int x,int a,int b){
if(c<=a&&b<=d){tag[x]=v[x]=p;return;}
pb(x);
int mid=(a+b)>>1;
if(c<=mid)change1(x<<1,a,mid);
if(d>mid)change1(x<<1|1,mid+1,b);
up(x);
}
void change2(int x,int a,int b){
if(v[x]<=p)return;
int mid=(a+b)>>1;
if(c<=a&&b<=d){
if(~tag[x])v[x]=tag[x]=gcd(tag[x],p);
else pb(x),change2(x<<1,a,mid),change2(x<<1|1,mid+1,b),up(x);
return;
}
pb(x);
if(c<=mid)change2(x<<1,a,mid);
if(d>mid)change2(x<<1|1,mid+1,b);
up(x);
}
void dfs(int x,int a,int b){
if(~tag[x]){for(;a<=b;a++)printf("%d ",tag[x]);return;}
int mid=(a+b)>>1;
dfs(x<<1,a,mid),dfs(x<<1|1,mid+1,b);
}
int main(){
read(T);
while(T--){
read(n);
for(i=1;i<=n;i++)read(s[i]);
build(1,1,n);
read(m);
while(m--)read(op),read(c),read(d),read(p),op==1?change1(1,1,n):change2(1,1,n);
dfs(1,1,n);
puts("");
}
return 0;
}

  

BZOJ3867 : Nice boat的更多相关文章

  1. Lesson 20 One man in a boat

    Text Fishing is my favourite sport. I often fish for hours without catching anything. But this does ...

  2. 【软件分析与挖掘】BOAT: An Experimental Platform for Researchers to Comparatively and Reproducibly Evaluate Bug Localization Techniques

    摘要: 目前有许多的bug定位技术,但是,由于他们基于不同的数据集,而且有些数据集还不是公开的,甚至有些技术只应用于小数据集,不具有通用性,因此,不好比较这些技术之间的优劣. 因此,BOAT应运而生. ...

  3. HDU 4902 Nice boat (线段树)

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

  4. HDU-4902 Nice boat

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  5. 【HDU】4092 Nice boat(多校第四场1006) ——线段树 懒惰标记

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  6. I think I need a boat house

    I think I need a boat house. Fred Mapper is considering purchasing some land in Louisiana to build h ...

  7. 线段树 + 区间更新 ----- HDU 4902 : Nice boat

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  8. UOJ#204 【APIO2016】Boat

    Time Limit: 70 Sec  Memory Limit: 256 MBSubmit: 559  Solved: 248 Description 在首尔城中,汉江横贯东西.在汉江的北岸,从西向 ...

  9. C++练习--创建Boat类和Car类(含友元)

    /* 定义Boat与Car两个类,二者都有weight属性, 定义二者的一个友元函数totalWeight()为外部函数, 计算二者的重量和. */ #include<iostream> ...

随机推荐

  1. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  2. 对于(function(){}())和function(){}实例的作用域分析(里面有很多问题……)

    今天在群里看到一个问题,让我纠结了好一会.下面是我的分析,感觉里面还有很多问题,关于作用域还是不太理解,希望大家看到问题第一时间反馈给我,看到实在受不了的地方说几句都没关系,谢谢. 请看题: 1.对象 ...

  3. 图像特征提取:Sobel边缘检测

    前言 点和线是做图像分析时两个最重要的特征,而线条往往反映了物体的轮廓,对图像中边缘线的检测是图像分割与特征提取的基础.文章主要讨论两个实际工程中常用的边缘检测算法:Sobel边缘检测和Canny边缘 ...

  4. win7系统扩展双屏幕时,如何在两个屏幕下都显示任务栏

    扩展屏幕下都显示任务栏!!! win7系统本身无法设置该功能(目前我是不知道) 但可以下载第三方软件来解决该问题. 第一步:Dual Monitor Taskbar 下载软件 下载链接:http:// ...

  5. Redis使用介绍

    Redis 是一个高性能的key-value数据库. redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部 分场合可以对关系数据库起到很好的补充作用.它提供了Pyth ...

  6. 【Hibernate】Hibernate系列8之管理session

    管理session 更简单的,注入对象:

  7. DP:Ant Counting(POJ 3046)

    数蚂蚁 题目大意:一只牛想数蚂蚁,蚂蚁分成很多组,每个组里面有很多只蚂蚁,现在问你有多少种组合方式 (说白了就是问1,1,1,...,2...,3...,4...)这些东西有多少种排列组合方式 这一道 ...

  8. July 29th, Week 31st Friday, 2016

    I am a slow walker, but I never walk backwards. 我走得很慢,但我从来不会后退. I had run very fast, and I had once ...

  9. javascript ASCII和Hex互转

    <script> var symbols = " !\"#$%&'()*+,-./0123456789:;<=>?@"; var loAZ ...

  10. LinuxC语言读取文件,分割字符串,存入链表,放入另一个文件

    //file_op.c #include <string.h> #include <stdio.h> #include <stdlib.h> struct info ...