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

## Sol

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e6 + 10, INF = 1e9 + 10;
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-')f =- 1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, a[MAXN];
#define ls k << 1
#define rs k << 1 | 1
struct Node {
int l, r, g;
}T[MAXN];
int gcd(int a, int b) {
return (b == 0 ? a : gcd(b, a % b));
}
void update(int k) {
T[k].g = gcd(T[ls].g, T[rs].g);
}
void Build(int k, int ll, int rr) {
T[k] = (Node) {ll, rr};
if(ll == rr) {T[k].g = a[ll]; return ;}
int mid = T[k].l + T[k].r >> 1;
Build(ls, ll, mid); Build(rs, mid + 1, rr);
update(k);
}
void PointChange(int k, int pos, int val) {
if(T[k].l == T[k].r) {T[k].g = val; return ;}
int mid = T[k].l + T[k].r >> 1;
if(pos <= mid) PointChange(ls, pos, val);
else PointChange(rs, pos, val);
update(k);
}
int sum = 0;
void IntervalTims(int k, int ll, int rr, int val) {
if(sum > 1) return ;
if(T[k].l == T[k].r) sum++;
int mid = T[k].l + T[k].r >> 1;
if(ll <= mid && (T[ls].g % val)) IntervalTims(ls, ll, rr, val);
if(rr  > mid && (T[rs].g % val)) IntervalTims(rs, ll, rr, val);
}
main() {
for(int i = 1; i <= N; i++) a[i] = read();
Build(1, 1, N);
while(M--) {
if(opt == 1) {
sum = 0; IntervalTims(1, l, r, x);
puts(sum > 1 ? "NO" : "YES");
} else {
PointChange(1, pos, x);
}
}
}
/*
*/

1811 篇文章121 人订阅

0 条评论

19550

6910

32860

47570

36280

23690

18320

24870

28900

8620