1 2 3 4

cf914 Bash and a Tough Math Puzzle

https://codeforc.es/contest/914/problem/D

Bash and a Tough Math Puzzle

开动脑筋暴力减枝,就是这样了,没啥可说的

#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 5e5+11;
typedef long long ll;

struct Node{
	ll ans;
}tree[maxn*4];

int update(int node,int be,int en,int i,int val){
	int mid = be + en >> 1;
	int l = node*2;
	int r = node*2+1;
	if(be == en ){
		tree[node].ans = val;
		return 0;
	}
	if(i <= mid) update(l,be,mid,i,val);
	else update(r,mid+1,en,i,val);
	tree[node].ans = __gcd(tree[l].ans,tree[r].ans);
	return 0;
}
int n, x;
int cnt = 0;
int aaa = 0;
int val;
int f = 0;






int ask(int node,int be,int en,int LL,int RR){
	if(f) return 0;
	
	
	int mid = be + en >> 1;
	int l = node*2;
	int r = node*2+1;
	if(be == en){
		if(tree[node].ans % val != 0){
			cnt++;
		}
		return 0;
	}
	
	if(LL <= be  && en <= RR){
		if(tree[node].ans % val == 0) return 0;
		if(be != en){
			if(tree[l].ans % val != 0 && tree[r].ans %val != 0){
				f = 1;
				return 0;
			}
		}
	}
	
	
	if(LL <= mid && tree[l].ans % val != 0) ask(l,be,mid,LL,RR);
	if(RR > mid && tree[r].ans % val != 0)  ask(r,mid+1,en,LL,RR);
	return 0;
}





int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		update(1,1,n,i,x);		
	}	
	int q;
	scanf("%d",&q);
	
	
	while(q--){
		int op;
		scanf("%d",&op);
		int x,y;
		if(op == 1){
			scanf("%d %d %d",&x,&y,&val);
			cnt = 0;
			f = 0;
			
			
			ask(1,1,n,x,y);
			
			
			if(f || cnt >= 2){
				printf("NO\n");
			}
			else{
				printf("YES\n");
			}
			
		}
		else{
			scanf("%d %d",&x,&val);
			update(1,1,n,x,val);
		}
	}
	
	
	
	return 0;
} 

  

posted @ 2020-12-18 20:28  Lesning  阅读(124)  评论(0编辑  收藏  举报