传送门

分析

用线段树维护区间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的更多相关文章

  1. Codeforces 914D - Bash and a Tough Math Puzzle 线段树,区间GCD

    题意: 两个操作, 单点修改 询问一段区间是否能在至多一次修改后,使得区间$GCD$等于$X$ 题解: 正确思路; 线段树维护区间$GCD$,查询$GCD$的时候记录一共访问了多少个$GCD$不被X整 ...

  2. Codeforces.914D.Bash and a Tough Math Puzzle(线段树)

    题目链接 \(Description\) 给定一个序列,两种操作:一是修改一个点的值:二是给一个区间\([l,r]\),问能否只修改一个数使得区间gcd为\(x\). \(Solution\) 想到能 ...

  3. 2018.12.08 codeforces 914D. Bash and a Tough Math Puzzle(线段树)

    传送门 线段树辣鸡题. 题意简述:给出一个序列,支持修改其中一个数,以及在允许自行修改某个数的情况下询问区间[l,r][l,r][l,r]的gcdgcdgcd是否可能等于一个给定的数. 看完题就感觉是 ...

  4. Codeforces 914D Bash and a Tough Math Puzzle (ZKW线段树)

    题目链接  Round #458 (Div. 1 + Div. 2, combined)  Problem D 题意  给定一个序列,两种询问:单点修改,询问某个区间能否通过改变最多一个数使得该区间的 ...

  5. [Codeforces 914D] Bash and a Tough Math Puzzle

    [题目链接] https://codeforces.com/contest/914/problem/D [算法] 显然 , 当一个区间[l , r]中为d倍数的数的个数 <= 1 , 答案为Ye ...

  6. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  7. 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区间能否去掉 ...

  8. D. Bash and a Tough Math Puzzle 解析(線段樹、數論)

    Codeforce 914 D. Bash and a Tough Math Puzzle 解析(線段樹.數論) 今天我們來看看CF914D 題目連結 題目 給你一個長度為\(n\)的數列\(a\), ...

  9. Bash and a Tough Math Puzzle CodeForces - 914D (线段树二分)

    大意:给定序列, 单点修改, 区间询问$[l,r]$内修改至多一个数后$gcd$能否为$x$ 这题比较有意思了, 要注意到询问等价于$[l,r]$内最多有1个数不为$x$的倍数 可以用线段树维护gcd ...

随机推荐

  1. js 对象可枚举属性以及for in 循环和for of 循环

    js中每个对象的属性(js里万物皆属性,对象的属性也是对象)都有一个属性叫enumerable(可枚举性),这个属性true/false决定了该对象的属性是否可枚举(就是让一些方法访问到这个属性). ...

  2. sql-多表查询JOIN与分组GROUP BY

    一.内部连接:两个表的关系是平等的,可以从两个表中获取数据.用ON表示连接条件 SELECT A.a,B.b FROM At AS A  INNER JOINT Bt AS B ON  A.m=B.n ...

  3. BZOJ5302: [Haoi2018]奇怪的背包

    BZOJ5302: [Haoi2018]奇怪的背包 https://lydsy.com/JudgeOnline/problem.php?id=5302 分析: 方程\(\sum\limits_{i=1 ...

  4. python基础准备

    老男孩python全栈学习day1 第一讲python基础: 1.python起源:python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中 ...

  5. Operating System-进程/线程内部通信-临界区(Critical Regions)

    上一篇文章讲述了进程之间的竞争条件:多个进程同时进入一个共享区域,导致了数据的不一致,本文主要介绍如何解决这个问题. 一.临界区介绍 解决这个问题就是阻止多个进程同时进入这个共享区域,换句话说,进程之 ...

  6. 命令行启动MySQL

    1 首先打开CMD,即命令行 输入mysqld ,如出现 则说明MySQL安装路径下的bin不在系统的环境变量中,你需要进入它的安装路径的bin目录下启动. ps:如果你不知道路径可以去开始菜单,找到 ...

  7. 机器学习:偏差方差权衡(Bias Variance Trade off)

    一.什么是偏差和方差 偏差(Bias):结果偏离目标位置: 方差(Variance):数据的分布状态,数据分布越集中方差越低,越分散方差越高: 在机器学习中,实际要训练模型用来解决一个问题,问题本身可 ...

  8. MongoDB优化之一:常见优化方法

    常用性能优化方案 创建索引 限定返回结果数 只查询使用到的字段 采用capped collection 采用Server Side Code Execution 使用Hint,强制使用索引 Hint ...

  9. AngularJS:事件

    ylbtech-AngularJS:事件 1.返回顶部 1. AngularJS 事件 AngularJS 有自己的 HTML 事件指令. ng-click 指令 ng-click 指令定义了 Ang ...

  10. git学习 删除远程分支

    2种方法删除远端分支: git branch -r -d origin/branch-name    // -r:  远端:    -d:删除 git push origin :branch-name ...