914D Bash and a Tough Math Puzzle
分析
用线段树维护区间gcd,每次查询找到第一个不是x倍数的点,如果这之后还有gcd不能被x整除的区间则这个区间不合法
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int d[],cnt,a[];
inline int gcd(int x,int y){return y==?x:gcd(y,x%y);}
inline void build(int le,int ri,int wh){
if(le==ri){
d[wh]=a[le];
return;
}
int mid=(le+ri)>>;
build(le,mid,wh<<);
build(mid+,ri,wh<<|);
d[wh]=gcd(d[wh<<],d[wh<<|]);
return;
}
inline void update(int le,int ri,int wh,int pl,int k){
if(le==ri){
d[wh]=k;
return;
}
int mid=(le+ri)>>;
if(mid>=pl)update(le,mid,wh<<,pl,k);
else update(mid+,ri,wh<<|,pl,k);
d[wh]=gcd(d[wh<<],d[wh<<|]);
return;
}
inline void q(int le,int ri,int wh,int x,int y,int k){
if(le>=x&&ri<=y){
if(d[wh]%k==)return;
if(cnt>=){
cnt++;
return;
}
}
if(le==ri){
cnt++;
return;
}
int mid=(le+ri)>>;
if(mid>=x)q(le,mid,wh<<,x,y,k);
if(mid<y)q(mid+,ri,wh<<|,x,y,k);
return;
}
int main(){
int n,m,i,j,k,x,y,z;
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d\n",&a[i]);
build(,n,);
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d",&k);
if(k==){
scanf("%d%d%d",&x,&y,&z);
cnt=;
q(,n,,x,y,z);
if(cnt>)puts("NO");
else puts("YES");
}else {
scanf("%d%d",&x,&y);
update(,n,,x,y);
}
}
return ;
}
914D Bash and a Tough Math Puzzle的更多相关文章
- Codeforces 914D - Bash and a Tough Math Puzzle 线段树,区间GCD
题意: 两个操作, 单点修改 询问一段区间是否能在至多一次修改后,使得区间$GCD$等于$X$ 题解: 正确思路; 线段树维护区间$GCD$,查询$GCD$的时候记录一共访问了多少个$GCD$不被X整 ...
- Codeforces.914D.Bash and a Tough Math Puzzle(线段树)
题目链接 \(Description\) 给定一个序列,两种操作:一是修改一个点的值:二是给一个区间\([l,r]\),问能否只修改一个数使得区间gcd为\(x\). \(Solution\) 想到能 ...
- 2018.12.08 codeforces 914D. Bash and a Tough Math Puzzle(线段树)
传送门 线段树辣鸡题. 题意简述:给出一个序列,支持修改其中一个数,以及在允许自行修改某个数的情况下询问区间[l,r][l,r][l,r]的gcdgcdgcd是否可能等于一个给定的数. 看完题就感觉是 ...
- Codeforces 914D Bash and a Tough Math Puzzle (ZKW线段树)
题目链接 Round #458 (Div. 1 + Div. 2, combined) Problem D 题意 给定一个序列,两种询问:单点修改,询问某个区间能否通过改变最多一个数使得该区间的 ...
- [Codeforces 914D] Bash and a Tough Math Puzzle
[题目链接] https://codeforces.com/contest/914/problem/D [算法] 显然 , 当一个区间[l , r]中为d倍数的数的个数 <= 1 , 答案为Ye ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- CF 914 D. Bash and a Tough Math Puzzle
D. Bash and a Tough Math Puzzle http://codeforces.com/contest/914/problem/D 题意: 单点修改,每次询问一段l~r区间能否去掉 ...
- D. Bash and a Tough Math Puzzle 解析(線段樹、數論)
Codeforce 914 D. Bash and a Tough Math Puzzle 解析(線段樹.數論) 今天我們來看看CF914D 題目連結 題目 給你一個長度為\(n\)的數列\(a\), ...
- Bash and a Tough Math Puzzle CodeForces - 914D (线段树二分)
大意:给定序列, 单点修改, 区间询问$[l,r]$内修改至多一个数后$gcd$能否为$x$ 这题比较有意思了, 要注意到询问等价于$[l,r]$内最多有1个数不为$x$的倍数 可以用线段树维护gcd ...
随机推荐
- Mat ,IplImage, CvMat 之间的转换的总结
在新版本与旧版本之间纠结,到底是用Mat,还是Iplimage? Mat 侧重于数据计算,而Iplimage注重于图像的处理. 因此,应根据具体需要灵活使用,那个好用用哪个,只要在两者之间进行转换即可 ...
- CERC2016 爵士之旅 Jazz Journey
传送门(洛谷) 题目大意 给定$n$个位置,和一个长为$m$的序列$A$,你需要经过一条直接的边从第$A_i$个位置到第$A_{i+1}$个位置. 每条有向边$(u,v)$分为两种,第一种可以花费$C ...
- [基本操作] Mobius 反演, Dirichlet 卷积和杜教筛
Dirichlet 卷积是两个定义域在正整数上的函数的如下运算,符号为 $*$ $(f * g)(n) = \sum_{d|n}f(d)g(\frac{n}{d})$ 如果不强调 $n$ 可简写为 $ ...
- C#进阶之路(一):委托
一.什么是委托 简单说它就是一个能把方法当参数传递的对象,而且还知道怎么调用这个方法,同时也是粒度更小的“接口”(约束了指向方法的签名). 委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方 ...
- LeetCode Binary Tree Tilt
原题链接在这里:https://leetcode.com/problems/binary-tree-tilt/description/ 题目: Given a binary tree, return ...
- 怪盗基德的滑翔翼(还是最长x序列)
//怪盗基德的滑翔翼 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstri ...
- 使用sort&awk实现文件内容块排序
源文件为: [root@luo5 wangxx]# cat -v luo.txt J LuoSoutth jfsaNanjing,china Y ZhangVictory UniversityNejf ...
- 4、运行成功的Demo(PyCharm+Selenium)
1.打开PyCharm,新建一个python.file,输入代码“from selenium import webdriver”报错的解决方法 (1)PyCharm没有找到正确的python,在“Fi ...
- Dockerfile 部署应用执行脚本文件
FROM centos6.6:0.0.1 MAINTAINER syberos:wangmo RUN mv /etc/yum.repos.d/ /etc/yum.repos.d_bak/ && ...
- hl7 v2.X 版本中RSP_K23消息的构造
RSP_K23消息有MSH, MSA, ERR, QAK, QPD, PID几个segment,其中ERR,PID为可选. 1. 当MSA有err时,ERR段填充出错的详细信息. 2. 当MSA为AA ...