[题目链接]

https://codeforces.com/contest/914/problem/D

[算法]

显然 , 当一个区间[l , r]中为d倍数的数的个数 <= 1 , 答案为Yes , 否则为No

线段树简单维护即可 , 详见代码 , 时间复杂度 : O(NlogN ^ 2)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + ; int n , m;
int val[MAXN];
int cnt; struct Segment_Tree
{
struct Node
{
int l , r;
int value;
} a[MAXN << ];
inline int gcd(int x , int y)
{
if (y == ) return x;
else return gcd(y , x % y);
}
inline void update(int x)
{
a[x].value = gcd(a[x << ].value , a[x << | ].value);
}
inline void build(int index , int l , int r)
{
a[index].l = l , a[index].r = r;
if (l == r)
{
a[index].value = val[l];
return;
}
int mid = (l + r) >> ;
build(index << , l , mid);
build(index << | , mid + , r);
update(index);
}
inline void modify(int index , int x , int y)
{
if (a[index].l == a[index].r)
{
a[index].value = y;
return;
} else
{
int mid = (a[index].l + a[index].r) >> ;
if (mid >= x) modify(index << , x , y);
else modify(index << | , x , y);
update(index);
}
}
inline void getans(int index , int l , int r , int d)
{
if (cnt > ) return;
int mid = (a[index].l + a[index].r) >> ;
if (a[index].l == l && a[index].r == r)
{
if (l == r)
{
if (a[index].value % d)
++cnt;
return;
}
if ((a[index << ].value % d) && (a[index << | ].value % d))
{
cnt += ;
return;
} else if (a[index << ].value % d) getans(index << , l , mid , d);
else if (a[index << | ].value % d) getans(index << | , mid + , r , d);
} else
{
if (mid >= r) getans(index << , l , r , d);
else if (mid + <= l) getans(index << | , l , r , d);
else
{
getans(index << , l , mid , d);
getans(index << | , mid + , r , d);
}
}
}
} SGT; template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ read(n);
for (int i = ; i <= n; i++) read(val[i]);
SGT.build( , , n);
read(m);
while (m--)
{
int type;
read(type);
if (type == )
{
int l , r , x;
read(l); read(r); read(x);
cnt = ;
SGT.getans( , l , r , x);
if (cnt > ) printf("NO\n");
else printf("YES\n");
} else
{
int x , y;
read(x); read(y);
SGT.modify( , x , y);
}
} return ;
}

[Codeforces 914D] Bash and a Tough Math Puzzle的更多相关文章

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

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

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

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

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

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

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

    题目链接  Round #458 (Div. 1 + Div. 2, combined)  Problem D 题意  给定一个序列,两种询问:单点修改,询问某个区间能否通过改变最多一个数使得该区间的 ...

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

    大意:给定序列, 单点修改, 区间询问$[l,r]$内修改至多一个数后$gcd$能否为$x$ 这题比较有意思了, 要注意到询问等价于$[l,r]$内最多有1个数不为$x$的倍数 可以用线段树维护gcd ...

随机推荐

  1. Hdu5921 Binary Indexed Tree

    Hdu5921 Binary Indexed Tree 思路 计数问题,题目重点在于二进制下1的次数的统计,很多题解用了数位DP来辅助计算,定义g(i)表示i的二进制中1的个数, $ans = \su ...

  2. (43)C#网络1 http

    一.HttpClient类 用于发送http请求,并接受请求的相应 (从4.5起开始可用) using System.Net.Http; 异步调用 HttpClient httpClient = ne ...

  3. BZOJ——1610: [Usaco2008 Feb]Line连线游戏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1610 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 2 ...

  4. codevs——1570 去看电影

    1570 去看电影  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 农夫约翰带着他的一些奶牛去看电影.而他的 ...

  5. java.nio.ByteBuffer 以及flip,clear及rewind区别

    Buffer 类 定义了一个可以线性存放primitive type数据的容器接口.Buffer主要包含了与类型(byte, char…)无关的功能. 值得注意的是Buffer及其子类都不是线程安全的 ...

  6. leetcode最长递增子序列问题

    题目描写叙述: 给定一个数组,删除最少的元素,保证剩下的元素是递增有序的. 分析: 题目的意思是删除最少的元素.保证剩下的元素是递增有序的,事实上换一种方式想,就是寻找最长的递增有序序列.解法有非常多 ...

  7. 课程的正确步调——Leo鉴书74

    <Leo鉴书(第1辑)>已登陆百度阅读.今后还将不断更新,免费下载地址:http://t.cn/RvawZEx 本人第一次站上讲台是1999年,那会儿从中关村回到天津,在一个给成人做计算机 ...

  8. HTML5已定稿:将彻底颠覆原生应用

    2007年W3C(万维网联盟)立项HTML5,直至2014年10月底.这个长达八年的规范最终正式封稿. 过去这些年.HTML5颠覆了PC互联网的格局,优化了移动互联网的体验,接下来.HTML5将颠覆原 ...

  9. C++中的链式操作

    代码编译环境:Windows7 32bits+VS2012. 1.什么是链式操作 链式操作是利用运算符进行的连续运算(操作).它的特点是在一条语句中出现两个或者两个以上相同的操作符,如连续的赋值操作. ...

  10. 【POJ 1716】Integer Intervals(差分约束系统)

    id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS   Memory L ...