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区间能否去掉小于等于1个数,使gcd为x
分析:
线段树。
线段树二分。如果一边的gcd不是x,那么递归这一边,找到这个位置为止,计算这样的位置的个数。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
#define Root 1, n, 1
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ; int gcd(int a,int b) {
return b == ? a : gcd(b, a % b);
} int g[N << ], G, cnt; void pushup(int rt) {
g[rt] = gcd(g[rt << ], g[rt << | ]);
}
void build(int l,int r,int rt) {
if (l == r) {
g[rt] = read(); return ;
}
int mid = (l + r) >> ;
build(lson), build(rson);
pushup(rt);
}
void update(int l,int r,int rt,int p,int v) {
if (l == r) {
g[rt] = v; return ;
}
int mid = (l + r) >> ;
if (p <= mid) update(lson, p, v);
else update(rson, p, v);
pushup(rt);
}
bool query(int l,int r,int rt,int L,int R) {
if (g[rt] % G == ) return true; // 如果区间gcd为G的倍数,那么这个区间合法
if (l == r) return (++cnt) <= ; // 否则递归下去,找到不合法的位置,计算有几个,大于1个不合法。
int mid = (l + r) >> ;
if (L > mid) query(rson, L, R);
else if (R <= mid) query(lson, L, R);
else return query(lson, L, R) && query(rson, L, R);
}
int main() {
int n = read();
build(Root);
int Q = read();
while (Q--) {
int opt = read();
if (opt == ) {
int l = read(), r = read(); G = read(); cnt = ;
puts(query(Root, l, r) ? "YES" : "NO");
}
else {
int p = read(), v = read();
update(Root, p, v);
}
}
return ;
}
CF 914 D. Bash and a Tough Math Puzzle的更多相关文章
- codeforces 914 D Bash and a Tough Math Puzzle
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #i ...
- 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 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- Codecraft-18 and Codeforces Round #458:D,Bash and a Tough Math Puzzle
题目传送门 题目大意:Bash喜欢对数列进行操作.第一种操作是询问l~r区间内的gcd值是否几乎为x,几乎为表示能否至多修改一个数达到.第二种操作是将ai修改为x.总共Q个询问,N个数. Soluti ...
- [Codeforces 914D] Bash and a Tough Math Puzzle
[题目链接] https://codeforces.com/contest/914/problem/D [算法] 显然 , 当一个区间[l , r]中为d倍数的数的个数 <= 1 , 答案为Ye ...
- 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是否可能等于一个给定的数. 看完题就感觉是 ...
- Bash and a Tough Math Puzzle CodeForces - 914D (线段树二分)
大意:给定序列, 单点修改, 区间询问$[l,r]$内修改至多一个数后$gcd$能否为$x$ 这题比较有意思了, 要注意到询问等价于$[l,r]$内最多有1个数不为$x$的倍数 可以用线段树维护gcd ...
随机推荐
- (fields.E130) DecimalFields must define a 'decimal_places' attribute.
DecimalField类型:固定精度的十进制数,一般用来存金额相关的数据.额外的参数包括DecimalField.max_digits(整个数字的长度)和DecimalField.decimal_p ...
- 在Ubuntu搭建网站环境问题记录
1. 安装apache2 遇到如下问题 root@louis:~# apt-get install apache2Reading package lists... DoneBuilding depen ...
- 阅读优秀的JAVA模板引擎Beetl的使用说明有感
由于项目需要,对包括Beetl在内的JAVA模板引擎技术进行了学习 Beetl是由国人李家智(昵称闲大赋)开发的一款高性能JAVA模板引擎,对标产品是Freemaker 感慨于近几年国内开源项目的蓬勃 ...
- 安卓渗透测试工具Drozer学习笔记
下载,并安装. pip安装即可,安装完成后可能会出现缺少twisted依赖库的问题 ➜ vul git:(master) ✗ drozer console connect drozer Server ...
- Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】
传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...
- MS12-020蓝屏攻击
MS12-020远程桌面协议RDP拒绝访问漏洞 条件:受害者必须开放RDP协议 开放了3389端口 或者端口改了,知道对方RDP开放的对应端口. 过程:MSF利用 MSF显示为seems down说明 ...
- 新建oracle实例
1.安装好ORACLE服务端.2.在开始菜单中,点击ORAHOME目录下的"Configuration and Migration Tools"下的"Database C ...
- 使用@AspectJ注解开发Spring AOP
一.实体类: Role public class Role { private int id; private String roleName; private String note; @Overr ...
- The Android ION memory allocator
http://lwn.net/Articles/480055/ Back in December 2011, LWN reviewed the list of Android kernel patch ...
- winform 里 如何实现文件上传
看了网上写的 用webclient类的uploadfile方法, 我在本地建立了个webform,winform窗体, 现在可以本地实现文件传递,可以选择文件传到d:\temp路径下,但怎们传到服务 ...