cf914D. Bash and a Tough Math Puzzle(线段树)
题意
Sol
直接在线段树上二分
当左右儿子中的一个不是\(x\)的倍数就继续递归
由于最多递归到一个叶子节点,所以复杂度是对的
开始时在纠结如果一段区间全是\(x\)的两倍是不是需要特判,实际上是不需要的。
可以这么想,如果能成功的话,我们可以把那个数改成\(1\),这样比\(x\)大的数就不会对答案产生影响了。
不过我的线段树为啥要开6倍空间才能过。。真是狗血、、
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e6 + 10, INF = 1e9 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-')f =- 1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, a[MAXN];
#define ls k << 1
#define rs k << 1 | 1
struct Node {
int l, r, g;
}T[MAXN];
int gcd(int a, int b) {
return (b == 0 ? a : gcd(b, a % b));
}
void update(int k) {
T[k].g = gcd(T[ls].g, T[rs].g);
}
void Build(int k, int ll, int rr) {
T[k] = (Node) {ll, rr};
if(ll == rr) {T[k].g = a[ll]; return ;}
int mid = T[k].l + T[k].r >> 1;
Build(ls, ll, mid); Build(rs, mid + 1, rr);
update(k);
}
void PointChange(int k, int pos, int val) {
if(T[k].l == T[k].r) {T[k].g = val; return ;}
int mid = T[k].l + T[k].r >> 1;
if(pos <= mid) PointChange(ls, pos, val);
else PointChange(rs, pos, val);
update(k);
}
int sum = 0;
void IntervalTims(int k, int ll, int rr, int val) {
if(sum > 1) return ;
if(T[k].l == T[k].r) sum++;
int mid = T[k].l + T[k].r >> 1;
if(ll <= mid && (T[ls].g % val)) IntervalTims(ls, ll, rr, val);
if(rr > mid && (T[rs].g % val)) IntervalTims(rs, ll, rr, val);
}
main() {
N = read();
for(int i = 1; i <= N; i++) a[i] = read();
Build(1, 1, N);
M = read();
while(M--) {
int opt = read();
if(opt == 1) {
int l = read(), r = read(), x = read();
sum = 0; IntervalTims(1, l, r, x);
puts(sum > 1 ? "NO" : "YES");
} else {
int pos = read(), x = read();
PointChange(1, pos, x);
}
}
}
/*
*/
cf914D. Bash and a Tough Math Puzzle(线段树)的更多相关文章
- CF914D Bash and a Tough Math Puzzle 线段树+gcd??奇怪而精妙
嗯~~,好题... 用线段树维护区间gcd,按如下法则递归:(记题目中猜测的那个数为x,改动次数为tot) 1.若子区间的gcd是x的倍数,不递归: 2.若子区间的gcd是x的倍数,且没有递归到叶子结 ...
- 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\) 想到能 ...
- CodeForces 914DBash and a Tough Math Puzzle(线段树的骚操作)
D. Bash and a Tough Math Puzzle time limit per test 2.5 seconds memory limit per test 256 megabytes ...
- [CF914D]Bash and a Tough Math Puzzle
给定一个数列$a_1,a_2,...,a_n$,支持两种操作 1 l r x,猜测数列中[l,r]位置上的数的最大公约数$x$,判断这个猜测是否是接近正确的.如果我们可以在数列[l,r]位置中改动至多 ...
- 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\), ...
- 2018.12.08 codeforces 914D. Bash and a Tough Math Puzzle(线段树)
传送门 线段树辣鸡题. 题意简述:给出一个序列,支持修改其中一个数,以及在允许自行修改某个数的情况下询问区间[l,r][l,r][l,r]的gcdgcdgcd是否可能等于一个给定的数. 看完题就感觉是 ...
随机推荐
- loj #6235. 区间素数个数 min_12.5筛
\(\color{#0066ff}{ 题目描述 }\) 求 \(1\sim n\) 之间素数个数. \(\color{#0066ff}{输入格式}\) 一行一个数 n . \(\color{#0066 ...
- 二分+最小生成树【bzoj2654】: tree
2654: tree 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有need条白色边的生成树. 题目保证有解. 二分答案,然后跑最小生成树判断. 注意优先跑白色边. code: ...
- [USACO10OCT]湖计数Lake Counting 联通块
题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is repres ...
- Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryDa ...
- jeesite 框架的简单应用
个人觉得比较完善的一个讲解jeesite的网站 https://www.w3cschool.cn/jeesite/ jeesite官网 http://jeesite.com/ 公司项目都是基于jees ...
- 2-32 while
do while
- win10 cmd 替换 powershell
打开注册表编辑器,定位至: \HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command cmd: cmd.exe /s /k p ...
- ARM,CPU相关概念
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 相关链接: ARM内核和架构都是什么意思,它们到底是什么关系?:ht ...
- linux学习四x系统指令
一.任务调度 任务调度:系统在某个时间执行特定的命令或者程序 如: 1.对于一些需要周期性执行的一些系统指令 2.定期的病毒扫描 3.定期数据库备份等 命令:crontab 设置任务调度文件: / ...
- my03_使用空数据库搭建Mysql主从复制
无数据的主从复制,就搭建一套主从结构的空库,这个是最简单的,先说说这种主从的搭建思路,有利于理解Mysql主从复制1. 安装两套mysql单实例数据库,一个作为主库.一个作为从库:注意要设置两个数据库 ...