嗯~~,好题。。。

用线段树维护区间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. JAVA-关键字&标识符

    关键字: 关键字就是在java程序中具备特殊含义的标识符.关键字一般用于描述一个程序的结构或者表示数据类型.他们用来表示一种数据类型,或者表示程序的结构等,关键字不能用作变量名.方法名.类名.包名. ...

  2. BZOJ 1641 [Usaco2007 Nov]Cow Hurdles 奶牛跨栏:新版floyd【路径上最大边最小】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1641 题意: 给你一个有向图,n个点(n <= 300),m条边,边权为h[i]. ...

  3. BZOJ 1191 [HNOI2006]超级英雄Hero:二分图匹配 匈牙利算法

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1191 题意: 有m道题,每答对一题才能接着回答下一个问题. 你一道题都不会,但是你有n个“ ...

  4. laravel基础课程---4、Laravel基础网站结构搭建

    laravel基础课程---4.Laravel基础网站结构搭建 一.总结 一句话总结: 1.搭建网站前后台路由:在路由组Route::group()中设置好命名空间和前缀 2.搭建控制器:比如1)新建 ...

  5. linux shell date 时间运算以及时间差计算方法

    最近一段时间,在处理Shell 脚本时候,遇到时间的处理问题. 时间的加减,以及时间差的计算. 获取当前时间戳 date +%s . 时间加减 这里处理方法,是将基础的时间转变为时间戳,然后,需要增加 ...

  6. create-react-app使用的问题

    // 设置 npm config set registry https://registry.npm.taobao.org // 验证是否成功 npm config get registry或npm ...

  7. 1072 Gas Station (30)(30 分)

    A gas station has to be built at such a location that the minimum distance between the station and a ...

  8. Words Gems

    所有的东西都来自抄袭.来自学习.不同的是用新的方法做其他公司做过的事情.很多公司做同样的事情,但只有一家公司最成功.你要发现一个有需求的服务,并做得比别人更好,而不是比别人更早.

  9. poj2955——括号匹配

    题目:http://poj.org/problem?id=2955 区间DP. 代码如下: #include<iostream> #include<cstdio> #inclu ...

  10. jQuery中attr()与prop()区别介绍

    .attr() : 获取匹配的元素集合中的第一个元素的属性的值 或 设置每一个匹配元素的一个或多个属性. •.attr( attributeName ) •.attr( attributeName ) ...