[题目链接]

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. hdu - 1269 迷宫城堡 (强连通裸题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1269 判断一个图是不是强连通,缩点之后判断顶点数是不是为1即可. #include <iostream&g ...

  2. 模拟赛QAQ

    100 + 30 + 0 T1 叉叉 题目描述 现在有一个字符串,每个字母出现的次数均为偶数.接下来我们把第一次出现的字母a和第二次出现的a连一条线,第三次出现的和四次出现的字母a连一条线,第五次出现 ...

  3. 深入理解iPhone数据持久化(手把手教你iphone开发 – 基础篇)

    在所有的移动开发平台数据持久化都是很重要的部分:在j2me中是rms或保存在应用程序的目录中,在symbian中可以保存在相应的磁盘目录中和数据库中.symbian中因为权限认证的原因,在3rd上大多 ...

  4. sqlalchemy的merge使用

    1.先看下文档 merge(instance, load=True) Copy the state of a given instance into a corresponding instance ...

  5. VC中常见API函数使用方法(经验版)

    ***********************************************声明*************************************************** ...

  6. 简单使用 Mvc 内置的 Ioc

    简单使用 Mvc 内置的 Ioc 本文基于 .NET Core 2.0. 鉴于网上的文章理论较多,鄙人不才,想整理一份 Hello World(Demo)版的文章. 目录 场景一:简单类的使用 场景二 ...

  7. Sublime Text使用

    安装Sublime Text Sublime 的安装比較简单,我们能够直接去官网http://www.sublimetext.com/,点击Download菜单.进入之后选择自己操作系统的进行下载安装 ...

  8. C# 通过window消息控制指定控件的scroll滚动

     [DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]         private st ...

  9. Java堆内存与栈内存对比

    在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有什么异同,以及和数据结构中的堆栈有何关系? 一.Java 堆存储空间 堆内存(堆存储空间)会在Java运行时分配 ...

  10. selenium-python问题日记

    今天在学习selenium时遇到了两个问题,在这里记录一下: 使用unittest框架组织了测试用例后,拓展一下功能就成了我最想做的事情, 所以决定添加发邮件功能. 使用python自带的smtpli ...