1 10 16807 282475249 1622650073 984943658 1144108930 470211272 101027544 1457850878 1458777923 2007237709 10 1 3 6 74243042 2 4 8 16531729 1 3 4 1474833169 2 1 8 1131570933 2 7 9 1505795335 2 3 7 101929267 1 4 10 1624379149 2 2 8 2110010672 2 6 7 156091745 1 2 5 937186357
16807 937186357 937186357 937186357 937186357 1 1 1624379149 1624379149 1624379149
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 100000+10;
int n,q;
int num[maxn];
struct node{
int lson,rson;
int maxx;
int num;
bool flag;
int mid(){
return (lson+rson)>>1;
}
}tree[maxn*4];
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
void pushUp(int rt){
tree[rt].maxx = max(tree[rt<<1].maxx,tree[rt<<1|1].maxx);
}
void pushDown(int rt){
if(tree[rt].flag){
tree[rt<<1].maxx = tree[rt<<1|1].maxx = tree[rt].maxx;
tree[rt<<1].flag = tree[rt<<1|1].flag = true;
tree[rt].flag = false;
}
}
void build(int L,int R,int rt){
tree[rt].lson = L;
tree[rt].rson = R;
tree[rt].flag = false;
if(L==R){
tree[rt].maxx = num[L];
tree[rt].flag = true;
return;
}
int mid = tree[rt].mid();
build(L,mid,rt<<1);
build(mid+1,R,rt<<1|1);
pushUp(rt);
}
void update1(int L,int R,int l,int r,int rt,int x){
if(L <= l && R >= r){
tree[rt].flag = true;
tree[rt].maxx = x;
return;
}
pushDown(rt);
int mid = tree[rt].mid();
if(L <= mid){
update1(L,R,l,mid,rt<<1,x);
}
if(R > mid){
update1(L,R,mid+1,r,rt<<1|1,x);
}
pushUp(rt);
}
void update2(int L,int R,int l,int r,int rt,int x){
if(tree[rt].maxx < x) return;
if(L <= l && R >= r && tree[rt].flag && tree[rt].maxx > x){
tree[rt].maxx = gcd(tree[rt].maxx,x);
return;
}
pushDown(rt);
int mid = tree[rt].mid();
if(L<=mid) update2(L,R,l,mid,rt<<1,x);
if(R>mid) update2(L,R,mid+1,r,rt<<1|1,x);
pushUp(rt);
}
void print(int L,int R,int rt){
if(L==R){
printf("%d ",tree[rt].maxx);
return;
}
pushDown(rt);
int mid = tree[rt].mid();
print(L,mid,rt<<1);
print(mid+1,R,rt<<1|1);
}
int main(){
int ncase;
cin >> ncase;
while(ncase--){
scanf("%d",&n);
for(int i = 1; i <= n; i++) scanf("%d",&num[i]);
build(1,n,1);
int a,b,c,d;
scanf("%d",&q);
while(q--){
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a==1){
update1(b,c,1,n,1,d);
}else{
update2(b,c,1,n,1,d);
}
}
print(1,n,1);
printf("\n");
}
return 0;
}
HDU4902-Nice boat(线段树),布布扣,bubuko.com
原文:http://blog.csdn.net/mowayao/article/details/38561089