BZOJ3867 : Nice boat
每个点最多被修改$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的更多相关文章
- Lesson 20 One man in a boat
Text Fishing is my favourite sport. I often fish for hours without catching anything. But this does ...
- 【软件分析与挖掘】BOAT: An Experimental Platform for Researchers to Comparatively and Reproducibly Evaluate Bug Localization Techniques
摘要: 目前有许多的bug定位技术,但是,由于他们基于不同的数据集,而且有些数据集还不是公开的,甚至有些技术只应用于小数据集,不具有通用性,因此,不好比较这些技术之间的优劣. 因此,BOAT应运而生. ...
- 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
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 【HDU】4092 Nice boat(多校第四场1006) ——线段树 懒惰标记
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- 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 ...
- 线段树 + 区间更新 ----- HDU 4902 : Nice boat
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- UOJ#204 【APIO2016】Boat
Time Limit: 70 Sec Memory Limit: 256 MBSubmit: 559 Solved: 248 Description 在首尔城中,汉江横贯东西.在汉江的北岸,从西向 ...
- C++练习--创建Boat类和Car类(含友元)
/* 定义Boat与Car两个类,二者都有weight属性, 定义二者的一个友元函数totalWeight()为外部函数, 计算二者的重量和. */ #include<iostream> ...
随机推荐
- Unity 烘焙材质到单一贴图的脚本
原地址:http://www.cocoachina.com/gamedev/gameengine/2011/0406/2756.html 这个脚本由 CocoaChina 版主 “四角钱” 分享,可以 ...
- UISerachBar / UISearchDisplayController
1. UISerachBar 继承与UIView, 包含uitextfield, 并且实现了uitextfielddelegate代理的主要内容 含有取消按钮, 默认不显示 2. UISerachDi ...
- ubuntu下git输出的颜色变化
(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 11点进家门,感觉很温暖哦. 以下是如何在用git的时候清晰的看出关键字的方法. $ vim ...
- 他们在军训,我在搞OI(三)
昨天忘记写了,因为急着去看 51nod 比赛,然而思考了许久还是一道都不会,好菜啊T_T... 补一下 Day 3 的情况. Day 3 上午还是常规地做 vjudge 上的套题,硬着头皮啃英文,感觉 ...
- Linux Apache和Nginx网络模型详解
进程阻塞和挂起的定义: 阻塞是由于进程所需资源得不到满足,并会最终导致进程被挂起 进程挂起的原因并不一定是由于阻塞,也有可能是时间片得不到满足,挂起状态是进程从内存调度到外存中的一种状态,若在 ...
- Laravel 5 系列入门教程(一)【最适合中国人的 Laravel 教程】
Laravel 5 系列入门教程(一)[最适合中国人的 Laravel 教程] 分享⋅ johnlui⋅ 于 2年前 ⋅ 最后回复由 skys215于 11个月前 ⋅ 17543 阅读 原文发表在 ...
- 追溯ASP.NET发展史
2000年全新平台的ASP.NET 1.0正式发布,发展速度异常惊人,2003年升级为1.1版本.ASP.NET 1.1发布之后,更加激发了Web应用程序开发人员对ASP.NET的兴趣,并且对网络技术 ...
- Flatten Binary Tree to Linked List
Flatten a binary tree to a fake "linked list" in pre-order traversal. Here we use the righ ...
- C++基础知识面试精选100题系列(1-10题)[C++ basics]
[原文链接] http://www.cnblogs.com/hellogiser/p/100-interview-questions-of-cplusplus-basics-1-10.html [题目 ...
- MVC登录案例
1.在Controllers文件夹里面新建一个控制器HomeController;2.在默认的Index方法里面添加一个视图,名字跟Controller中的方法名一样叫Index,添加后的视图文件会在 ...