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> ...
随机推荐
- 关于 CAS 不能登录的问题
经过排查,是因为 Capistrano 部署中设置了 http_proxy.此时通过 cas.m.xxxx.com 域名去访问 CAS 服务时,就不通了,需要修改为 IP 来访问. 但是公司的 CAS ...
- 开发jquery tab 插件
开发最简单的效果- -,基本构架 html,可以换更有意义的结构,这里demo,就简单写,不考虑SEO <div id="tab-hd"> <div class= ...
- Correlation Filter in Visual Tracking
涉及两篇论文:Visual Object Tracking using Adaptive Correlation Filters 和Fast Visual Tracking via Dense Spa ...
- 在ubuntu 15.04下安装VMware Tools
提出问题:在Ubuntu 15. 04版本上,不能实现剪贴板的共享 解决方法:发现没有装VMware Tools 安装VMware Tools步骤 1. 点击菜单栏,虚拟机 → 安装VMware工具 ...
- poj1094 拓扑 Sorting It All Out
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29744 Accepted: 10 ...
- 【Python】Django Model 怎么使用 UUID 作为主键?
>>> import uuidprint uuid.uuid3(uuid.uuid1(), 'python.org') >>> # make a UUID base ...
- 【Other】推荐点好听的钢琴曲
2013-12-13 16:19 匿名 | 浏览 138977 次 音乐钢琴 推荐点好听的钢琴曲,纯音乐也可以thanks!!! 2013-12-14 19:34 网友采纳 热心网友 巴洛克:帕海贝尔 ...
- Android的Observable和iOS的NotificationCenter
使用起来很类似,参看以下网址http://stackoverflow.com/questions/10327200/equivalent-of-ios-nsnotificationcenter-in- ...
- jQuery结合Ajax实现简单的前端验证和服务端查询
上篇文章写了简单的前端验证由传统的JavaScript转向流畅的jQuery滑动验证,现在拓展一下,使用Ajax实现用户体验比较好的异步查询,同样还是从建立一个简单的表单开始 <form nam ...
- 利用 FFmpeg 和 ImageMagick, AVI 转 GIF(不失真)
利用[TMPGEnc 4.0 XPress] 或 [TMPGEnc Video Mastering Works 5] 生成 AVI 这个视频编辑软件,可对每个帧进行操作 1.生成每个帧的 PNG ff ...