题目链接  Round #458 (Div. 1 + Div. 2, combined)  Problem D

题意  给定一个序列,两种询问:单点修改,询问某个区间能否通过改变最多一个数使得该区间的$gcd$值为$val$。

问题转化为询问某个区间里不是val的倍数的数的个数是否不超过$1$。

用线段树实现即可。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int A = 20; int t[1 << A];
int n, q, k, actn; inline int query(int i, int l, int r, int L, int R, int val){
if (t[i] % val == 0) return 1;
if (i >= n){
if (!--k) return 0;
return 1;
} int mid = (l + r) >> 1;
if (L <= mid){
if (!query(i << 1 , l , mid , L , min(mid, R) , val)) return 0;
}
if (R > mid){
if (!query(i << 1 | 1, mid + 1, r , max(mid + 1, L), R , val)) return 0;
}
return 1;
} inline void update(int x, int val){
t[x += n] = val;
for (; x >>= 1;) t[x] = __gcd(t[x << 1], t[x << 1 | 1]);
} int main(){ scanf("%d", &actn);
n = 1 << 19; rep(i, 0, actn - 1){
int x;
scanf("%d", &x);
t[i + n] = x;
} dec(i, n - 1, 1) t[i] = __gcd(t[i << 1], t[i << 1 | 1]); scanf("%d", &q);
while (q--){
int op;
scanf("%d", &op); if (op == 1){
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
k = 2;
puts(query(1, 0, n - 1, x - 1, y - 1, z) ? "YES" : "NO");
} else{
int x, y;
scanf("%d%d", &x, &y);
update(x - 1, y);
}
} return 0;
}

  

Codeforces 914D Bash and a Tough Math Puzzle (ZKW线段树)的更多相关文章

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

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

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

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

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

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

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

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

  5. 914D Bash and a Tough Math Puzzle

    传送门 分析 用线段树维护区间gcd,每次查询找到第一个不是x倍数的点,如果这之后还有gcd不能被x整除的区间则这个区间不合法 代码 #include<iostream> #include ...

  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. Codecraft-18 and Codeforces Round #458:D,Bash and a Tough Math Puzzle

    题目传送门 题目大意:Bash喜欢对数列进行操作.第一种操作是询问l~r区间内的gcd值是否几乎为x,几乎为表示能否至多修改一个数达到.第二种操作是将ai修改为x.总共Q个询问,N个数. Soluti ...

随机推荐

  1. Kinect关于PlayerIndex和SkeletonId之间的关系。

    项目中要锁定玩家骨骼后抠图, 一时没有灵感.google 关键词: the ralationship about skeletonid and playerindex. 结论: Player Segm ...

  2. jpg、png、gif图片格式的浅析

    原文地址:图片格式与设计那点事儿 之前面试时被面试官问到了jpg.gif.png格式的区别,当时就扯了一些,感觉都是扯淡,上网搜了下,分享一篇文章 第一次写技术博客,有不尽如人意的地方,还请见谅和指正 ...

  3. Kotlin的数据类:节省很多行代码(KAD 10)

    作者:Antonio Leiva 时间:Jan 25, 2017 原文链接:https://antonioleiva.com/data-classes-kotlin/ 在前面的文章中,我们已经见到了类 ...

  4. 开源api文档

    蒲公英——API文档 https://www.pgyer.com/doc/api

  5. 基于vue 2.X和高德地图的vue-amap组件获取经纬度

    今天我就讲了一下怎么通过vue和高德地图开发的vue-amap组件来获取经纬度. 这是vue-amap的官网文档:https://elemefe.github.io/vue-amap/#/ 这是我的码 ...

  6. Qt(1)

    Qt Qt开发图形界面软件,可以跨win.linux.mac平台.移动端,使用c++开发 Qt采用所见即所得的UI设计(UI设计和代码是联动的),GUI界面编辑信号和槽,由开发环境自动生成c++代码, ...

  7. iptables的配置文件/etc/sysconfig/iptables不存在 linux防火墙开关命令

    某linux服务器,使用 cat /etc/sysconfig/iptables命令时, 找不到文件. 1. service iptables status 使用该命令检查状态 如果之前找不到配置文件 ...

  8. Python3基本语法

    #编码 ''' 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串. 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 ...

  9. django orderby

    https://www.douban.com/group/topic/44329052/

  10. beta版本前准备

    目录 过去存在的问题 任务分工 开发规范 后端总结 卉卉 家灿 前端总结 绪佩 青元 恺琳 宇恒 丹丹 算法&API接口 家伟 鸿杰 一好 文档&博客撰写 政演 产品功能 我们已经做了 ...