题目链接  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. BInder浅析

    Binder是什么 Binder是运行在Android内核态用于进程间通信(IPC)的驱动,采用C/S架构,由三项基本组件组成:Binder服务端,Binder驱动,应用程序客户端. 为什么要用Bin ...

  2. spring 笔记2:Spring MVC : Did not find handler method for 问题的解决

    日志显示为: Looking up handler method for path /***Did not find handler method for [/***]No mapping found ...

  3. Node应用进程管理器pm2的使用

    本文转载自:豆瓣-PM2介绍 更多内容见github上的pm2说明文档pm2 pm2 是一个带有负载均衡功能的Node应用的进程管理器. 当你要把你的独立代码利用全部的服务器上的所有CPU,并保证进程 ...

  4. lshw

    https://linux.die.net/man/1/lshw lshw(Hardware Lister)是另外一个可以查看硬件信息的工具,不仅如此,它还可以用来做一些硬件的benchmark. 这 ...

  5. 聊聊、Spring ServletContainerInitializer

    我们平时用 Java 注解很多,例如 @Configuration.@Component.@Service,我们习惯于通过 XML 方式来实现 Web,而用 Java 注解方式来实现 Web 却很少. ...

  6. springboot09 事务 H2数据库

    一.事务 1. 事务介绍 事务可以包含多个操作步骤 , 如果有一个步骤失败,那么这一组都以失败告终. 事务是指包含多个微小逻辑单元的一组操作, 只要其中有一个逻辑失败了,那么这一组操作就全部以失败告终 ...

  7. css 外边距,内边距的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 蓝桥杯_风险度量_dfs_无向图两节点间的所有路径

    标题:风险度量 X星系的的防卫体系包含 n 个空间站.这 n 个空间站间有 m 条通信链路,构成通信网.两个空间站间可能直接通信,也可能通过其它空间站中转. 对于两个站点x和y (x != y), 如 ...

  9. 设计模式之单例模式与工厂模式的Python实现(一)

    1. 单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上 ...

  10. BZOJ1004 [HNOI2008]Cards 【burnside定理 + 01背包】

    题目链接 BZOJ1004 题解 burnside定理 在\(m\)个置换下本质不同的染色方案数,等于每种置换下不变的方案数的平均数 记\(L\)为本质不同的染色方案数,\(m\)为置换数,\(f(i ...