HDU 4902
数据太弱,直接让我小暴力一下就过了,一开始没注意到时间是15000MS,队友发现真是太给力了
#include <cstdio>
#include <cstring>
int n,q,a[],x[],p,l[],r[],t[];
int tree[];
void build(int l, int r, int rt)
{
tree[rt]=-;
if(l==r){
tree[rt]=;
return;
}
int m=(l+r)/;
build(l,m,rt*);
build(m+,r,rt*+);
}
void update(int x, int y, int z, int l, int r, int rt)
{
if(x<=l&&y>=r){
tree[rt]=z;
return;
}
if(tree[rt]!=-) {
tree[rt*]=tree[rt];
tree[rt*+]=tree[rt];
tree[rt]=-;
}
int m=(l+r)/;
if(x<=m) update(x,y,z,l,m,rt*);
if(y>m) update(x,y,z,m+,r,rt*+);
}
int query(int k, int l, int r, int rt)
{
if(tree[rt]!=-) return tree[rt];
int m=(l+r)/;
if(k<=m) return(query(k,l,m,rt*));
else return(query(k,m+,r,rt*+));
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--){
memset(tree,-,sizeof(tree));
scanf("%d",&n);
build(,n,);
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
scanf("%d",&q);
for(int i=; i<=q; i++)
{
scanf("%d%d%d%d",&t[i],&l[i],&r[i],&x[i]);
if(t[i]==) update(l[i],r[i],i,,n,);
}
for(int i=; i<=n; i++){
p=query(i,,n,);
if(p) a[i]=x[p];
for(int j=p+; j<=q; j++)
if(t[j]==&&l[j]<=i&&r[j]>=i){
if(a[i]>x[j]){
int aa=a[i],bb=x[j],t=aa%bb;
while(t!=){
aa=bb;
bb=t;
t=aa%bb;
}
a[i]=bb;
}
}
}
for(int i=; i<=n; i++)
printf("%d ",a[i]);
printf("\n");
}
}
CLJ给出的正确题解:

既然gcd(a[i],x)<0.5a[i]
那么最多每个数字修改不会超过32次,
应该便是储存区间最大值以及增加判断区间内数字是否一致的flag
每次对于区间最大值>x的区间进行修改,最差情况无非是每个数字都不同,且数字都大于x,nlgn,而最多就修改32次,因此最差情况nlg^2n。
虽然证明麻烦,但是凭借感觉还是能够明白的。
实现相对简单便不再累赘。
HDU 4902的更多相关文章
- HDU 4902 (线段树)
Problem Nice boat(HDU 4902) 题目大意 维护一个序列,两种操作. 第一种操作,将一段区间[l,r]赋值为x. 第二种操作,将一段区间[l,r]中大于等于x的数与x求gcd. ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 4902 Nice boat (线段树)
Nice boat 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4902 Description There is an old country a ...
- hdu 4902 线段树+逆向模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4902 出n个数,然后对这n个数进行两种操作: 如果是 1 l r x,则把 [l, r] 区间里面的每一个数都变 ...
- hdu 4902 Nice boat(线段树区间改动,输出终于序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 Problem Description There is an old country and ...
- hdu 4902 Nice boat--2014 Multi-University Training Contest 4
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...
- HDU 4902 Nice boat --线段树(区间更新)
题意:给一个数字序列,第一类操作是将[l,r]内的数全赋为x ,第二类操作是将[l,r]中大于x的数赋为该数与x的gcd,若干操作后输出整个序列. 解法: 本题线段树要维护的最重要的东西就是一个区间内 ...
- 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)
题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...
- hdu 4902 Nice boat 线段树
题目链接 给n个数, 两种操作, 第一种是将区间内的数变成x, 第二种是将区间内大于x的数变为gcd(x, a[i]). 开三个数组, 一个记录区间最大值, 这样可以判断是否更新这一区间, 一个laz ...
随机推荐
- nodejs小问题:express不是内部或外部命令(转载)
安装express之后发现居然提示express不是内部或外部命令. 工具/原料 Node.js安装包 方法/步骤 1 首先下载Node.js安装包,此处我用的是官方最新的v0.10.27 32位版: ...
- LintCode-Unique Path II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- MITK Tutorial (三)
Step 2: Use the template with the plugins to read a image 在exampleplugin插件中QmitkAwesomeView.cpp中添加头文 ...
- BAT CMD 批处理文件脚本 -1
http://www.cnblogs.com/linglizeng/archive/2010/01/29/Bat-CMD-ChineseVerion.html 1. 综述 ...
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets
题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为 ...
- c#中获取服务器IP,客户端IP以及其它
客户端ip:Request.ServerVariables.Get("Remote_Addr").ToString();客户端主机名:Request.ServerVariables ...
- 基于AgileEAS.NET企业应用开发平台的分布式解决方案
开篇 分布式应用 AgileEAS.NET基于Microsoft .Net构件技术而构建,Microsoft .Net最吸引人的莫过于分布式应用技术,基已经提供了XML WebService. .Ne ...
- error: The shader requires a sampler in slot 0 which hasn't been set [XXXsampler]
About the sampler, you need to assign it to your pixelshader. m_d3dContext.Get()->PSSetSamplers(0 ...
- redis 资料链接
redis 资料链接 http://blog.nosqlfan.com/html/3537.html
- Eclipse下如何导入jar包
原地址:http://blog.csdn.net/justinavril/article/details/2783182 我们在用Eclipse开发程序的时候,经常想要用到第三方的jar包.这时候我们 ...