文件详细信息
本文件的大小为 2461 字节。
#include<cstdio>
namespace IO{
const int ARR_SIZE=1<<24;
#define gc() ((IO::si!=IO::ti||(IO::ti=(IO::si=IO::input)+fread(IO::input,1,IO::ARR_SIZE,stdin))),*(IO::si++))
#define pc(ch) ((IO::o.so!=IO::o.to||(fwrite(IO::o.output,1,IO::ARR_SIZE,stdout),IO::o.so=IO::o.output)),*(IO::o.so++)=ch)
char input[ARR_SIZE],*si=input,*ti=input;
struct Output_Stream{
char output[ARR_SIZE],*so=output,*to=output+ARR_SIZE;
~Output_Stream(){
if(so==output)return;
fwrite(output,1,so-output,stdout);
so=output;
}
}o;
template<typename T>
void read(T&num){
int ch=gc();
num=0;
while(ch<48||ch>57)ch=gc();
while(ch>=48&&ch<=57)num=(num<<3)+(num<<1)+(ch^48),ch=gc();
}
void getstr(char*str){
char ch=gc();
while(ch=='\r'||ch=='\n'||ch==' '||ch=='\t')ch=gc();
while(ch!='\r'&&ch!='\n'&&ch!=' '&&ch!='\t')*(str++)=ch,ch=gc();
}
template<typename T>
void write(T a){
static int ch[50],cnt;
if(a==0)pc('0');
cnt=0;
while(a)ch[++cnt]=a%10|48,a/=10;
while(cnt)pc(ch[cnt--]);
}
void putstr(char*str){
while(*str!='\0')pc(*(str++));
}
void putstr(const char*str){
while(*str!='\0')pc(*(str++));
}
}
using IO::read;
using IO::getstr;
using IO::write;
using IO::putstr;
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
const int maxn=500005;
int n,a[maxn],q,opt,l,r,x,y,t[maxn<<2];
auto pushup=[](int u){
t[u]=gcd(t[u<<1],t[u<<1|1]);
};
void build(int u,int l,int r){
if(l==r){
t[u]=a[l];
return;
}
int m=(l+r)>>1;
build(u<<1,l,m);
build(u<<1|1,m+1,r);
pushup(u);
}
void modify(int u,int l,int r,int x,int val){
if(l==r){
t[u]=val;
return;
}
int m=(l+r)>>1;
if(x<=m)modify(u<<1,l,m,x,val);
else modify(u<<1|1,m+1,r,x,val);
pushup(u);
}
int query(int u,int l,int r,int ql,int qr,int x){
int m=(l+r)>>1;
if(ql<=l&&r<=qr){
if(t[u]%x==0)return 0;
if(l==r)return 1;
if(t[u<<1]%x==0)return query(u<<1|1,m+1,r,ql,qr,x);
if(t[u<<1|1]%x==0)return query(u<<1,l,m,ql,qr,x);
return 2;
}
//ans=0 -> all correct
//ans=1 -> almost correct
//ans=2 -> wrong
int l_ans=0;
if(ql<=m)l_ans=query(u<<1,l,m,ql,qr,x);
if(qr>m){
int r_ans=query(u<<1|1,m+1,r,ql,qr,x);
if(l_ans+r_ans<=1)return l_ans+r_ans;
else return 2;
}
return l_ans;
}
int main(){
read(n);
for(int i=1;i<=n;i++)read(a[i]);
build(1,1,n);
read(q);
while(q--){
read(opt);
if(opt==1){
read(l),read(r),read(x);
putstr(query(1,1,n,l,r,x)<=1?"YES\n":"NO\n");
}else{
read(x),read(y);
modify(1,1,n,x,y);
}
}
return 0;
}