嗯~~,好题。。。

用线段树维护区间gcd,按如下法则递归:(记题目中猜测的那个数为x,改动次数为tot)

  1.若子区间的gcd是x的倍数,不递归;

  2.若子区间的gcd不是x的倍数,且没有递归到叶子结点,那么向下递归

  3.若递归到叶子结点,说明这个数需要改动,++tot

  4.若在任意时刻有tot>1,则直接return(不符题意)

#include<cstdio>
#include<iostream>
#define ll long long
#define R register int
#define pc(x) putchar(x)
#define ls (tr<<1)
#define rs (tr<<1|1)
const int M=;
using namespace std;
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
int n,m,tot;
int sum[M<<];
inline int gcd(int a,int b) {return b?gcd(b,a%b):a;}
inline void build(int tr,int l,int r) {
if(l==r) {sum[tr]=g(); return ;} R md=(l+r)>>;
build(ls,l,md),build(rs,md+,r); sum[tr]=gcd(sum[ls],sum[rs]);
}
inline void update(int tr,int l,int r,int pos,int inc) {
if(l==r) {sum[tr]=inc; return ;} R md=(l+r)>>;
if(pos<=md) update(ls,l,md,pos,inc); else update(rs,md+,r,pos,inc);
sum[tr]=gcd(sum[ls],sum[rs]);
}
inline void query(int tr,int l,int r,int LL,int RR,int mod) {
if(tot>) return ; if(l==r) { ++tot; return ;} R md=(l+r)>>;
if(LL<=md&&sum[ls]%mod) query(ls,l,md,LL,RR,mod); if(RR>md&&sum[rs]%mod) query(rs,md+,r,LL,RR,mod);
}
signed main() {
n=g(); build(,,n); m=g();
for(R i=;i<=m;++i) {
R k=g(),l=g(),r=g(),mod;
if(k&) {
mod=g(),tot=,query(,,n,l,r,mod);
tot>?(pc('N'),pc('O')):(pc('Y'),pc('E'),pc('S')); pc('\n');
} else update(,,n,l,r);
}
}

2019.04.19

CF914D Bash and a Tough Math Puzzle 线段树+gcd??奇怪而精妙的更多相关文章

  1. cf914D. Bash and a Tough Math Puzzle(线段树)

    题意 题目链接 Sol 直接在线段树上二分 当左右儿子中的一个不是\(x\)的倍数就继续递归 由于最多递归到一个叶子节点,所以复杂度是对的 开始时在纠结如果一段区间全是\(x\)的两倍是不是需要特判, ...

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

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

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

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

  4. 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 ...

  5. [CF914D]Bash and a Tough Math Puzzle

    给定一个数列$a_1,a_2,...,a_n$,支持两种操作 1 l r x,猜测数列中[l,r]位置上的数的最大公约数$x$,判断这个猜测是否是接近正确的.如果我们可以在数列[l,r]位置中改动至多 ...

  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. 2018.12.08 codeforces 914D. Bash and a Tough Math Puzzle(线段树)

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

随机推荐

  1. svn安装以及汉化过程

    第一步 下载svn地址 https://tortoisesvn.net/downloads.html 第二步一路next 最后finish 完成 就是完成svn的流程 第三步就是安装语言包 安装包语言 ...

  2. HTml js 生成图片

    <script type="text/javascript"> function $(id) { return document.getElementById(id); ...

  3. python 之生成器

    斐波拉契数列: In [31]: def func(times): ...: alist = [0,1] ...: sum = 0 ...: for i in range(times): ...: . ...

  4. BZOJ_3744_Gty的妹子序列

    BZOJ3744: Gty的妹子序列 https://lydsy.com/JudgeOnline/problem.php?id=3744 分析: 预处理出来每一块块首到所有位置的逆序对数. 查询时主席 ...

  5. 「LuoguP2365」 任务安排(dp

    题目描述 N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分批加工,第i个任务单独完成所需的时间是Ti. 在每批任务开 ...

  6. ACM学习历程—Codeforces 446C DZY Loves Fibonacci Numbers(线段树 && 数论)

    Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence ...

  7. vs2012解决scanf,printf编译出错的问题

    转自http://www.th7.cn/Program/c/201303/127343.shtml 在VS 2012 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: er ...

  8. bzoj 1202 [HNOI2005]狡猾的商人——带偏移量的并查集

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1202 带偏移量的并查集. 注意先 find() 再调用 dis !!! 自己的对拍太水了. ...

  9. raid0和raid5的 实验过程

    raid:独立的磁盘冗余阵列 创建raid0: 环境准备:准备三块大小相同的磁盘或分区,此处要特别注意:红色字体 [root@localhost6 home]#fdisk /dev/sdd ##对/d ...

  10. Javascript Tip(!!)

    var a:var b=!!a; a默认是undefined.!a是true,!!a则是false,所以b的值是false,而不再是undefined,也非其它值,主要是为后续判断提供便利. !!一般 ...