[题目链接]

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. 第一行代码 Android 思维导图

    第一行代码 Android  思维导图

  2. PostgreSQL SystemTap on Linux

    http://digoal126.wap.blog.163.com/w2/blogDetail.do;jsessionid=3949B03DE151DA0E55D807466C5E630B.yqblo ...

  3. 实时获取键盘高度 CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    注意:要想实时获取键盘的高度,比如当前如果是中文那么就会增高的.那么需要使用  UIKeyboardFrameEndUserInfoKey 而不是 UIKeyboardFrameBeginUserIn ...

  4. 应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为

    应用程序中的server错误,没有名称为"ServiceBehavior"的服务行为         今天在阅读"创建和使用Web服务"的相关内容,在浏览器中查 ...

  5. 基于Lua插件化的Pcap流量监听代理

    1.前言 我们在实际工作中,遇到了一个这样的用例,在每天例行扫描活动中,发现有些应用系统不定期的被扫挂,因为我们不是服务的制造者,没有办法在不同的系统里打印日志,所以我们就想用一个工具来获取特定服务的 ...

  6. 利用Loader来动态载入不同的QML文件来改变UI

    在这篇文章中.我们将介绍怎样使用Loader来载入不同的QML文件来实现动态的UI.在之前的文章"怎样使用Loader来动态载入一个基于item的Component"中,我们已经介 ...

  7. 【转载】.NET Remoting学习笔记(三)信道

    目录 .NET Remoting学习笔记(一)概念 .NET Remoting学习笔记(二)激活方式 .NET Remoting学习笔记(三)信道 参考:♂风车车.Net .NET Framework ...

  8. Comparable 和 Comparator的理解

    对Comparable 的解释 Comparable是一个排序接口 此接口给实现类提供了一个排序的方法,此接口有且只有一个方法 public int compareTo(T o); compareTo ...

  9. Linux下VLAN功能的实现 (转)

    1.Linux网络栈下两层实现 1.1简介     VLAN是网络栈的一个附加功能,且位于下两层.首先来学习Linux中网络栈下两层的实现,再去看如何把VLAN这个功能附加上去.下两层涉及到具体的硬件 ...

  10. CodeChef - COUNTARI FTT+分块

    Arithmetic Progressions Given N integers A1, A2, …. AN, Dexter wants to know how many ways he can ch ...