hdu 4902 Nice boat 线段树
给n个数, 两种操作, 第一种是将区间内的数变成x, 第二种是将区间内大于x的数变为gcd(x, a[i])。
开三个数组, 一个记录区间最大值, 这样可以判断是否更新这一区间, 一个lazy标记, 还有一个num数组记录这一区间的数是否相同, 如果不同则为-1。然后暴力更新就可以
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e5+;
int maxx[maxn<<], cnt[maxn<<], num[maxn<<];
void pushUp(int rt) {
if(num[rt<<] == num[rt<<|])
num[rt] = num[rt<<];
else
num[rt] = -;
maxx[rt] = max(maxx[rt<<], maxx[rt<<|]);
}
void pushDown(int rt) {
if(~cnt[rt]) {
cnt[rt<<] = cnt[rt<<|] = cnt[rt];
num[rt<<] = num[rt<<|] = num[rt];
maxx[rt<<] = maxx[rt<<|] = maxx[rt];
cnt[rt] = -;
}
}
void update(int val, int L, int R, int l, int r, int rt) {
if(L<=l&&R>=r) {
cnt[rt] = maxx[rt] = num[rt] = val;
return ;
}
pushDown(rt);
int m = l+r>>;
if(L<=m)
update(val, L, R, lson);
if(R>m)
update(val, L, R, rson);
pushUp(rt);
}
void update1(int L, int R, int l, int r, int rt, int val) {
if(L<=l&&R>=r&&num[rt]>val) {
cnt[rt] = maxx[rt] = num[rt] = __gcd(num[rt], val);
return ;
}
pushDown(rt);
int m = l+r>>;
if(L<=m&&maxx[rt<<]>val)
update1(L, R, lson, val);
if(R>m&&maxx[rt<<|]>val)
update1(L, R, rson, val);
pushUp(rt);
}
void build(int l, int r, int rt) {
if(l == r) {
scanf("%d", &maxx[rt]);
num[rt] = maxx[rt];
return ;
}
int m = l+r>>;
build(lson);
build(rson);
pushUp(rt);
}
void print(int l, int r, int rt) {
if(l == r) {
printf("%d ", num[rt]);
return ;
}
pushDown(rt);
int m = l+r>>;
print(lson);
print(rson);
}
int main()
{
int t, n, z, q, x, y, sign;
cin>>t;
while(t--) {
cin>>n;
build(, n, );
cin>>q;
mem1(cnt);
while(q--) {
scanf("%d%d%d%d", &sign, &x, &y, &z);
if(sign == ) {
update(z, x, y, , n, );
} else {
update1(x, y, , n, , z);
}
}
print(, n, );
cout<<endl;
}
}
hdu 4902 Nice boat 线段树的更多相关文章
- HDU 4902 Nice boat --线段树(区间更新)
题意:给一个数字序列,第一类操作是将[l,r]内的数全赋为x ,第二类操作是将[l,r]中大于x的数赋为该数与x的gcd,若干操作后输出整个序列. 解法: 本题线段树要维护的最重要的东西就是一个区间内 ...
- HDU 4902 Nice boat 线段树+离线
据说暴力也过了.还傻逼地写了这么长. . . #include <stdio.h> #include <string.h> #include <math.h> #i ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 4902 Nice boat (线段树)
Nice boat 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4902 Description There is an old country a ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- 线段树 + 区间更新 ----- HDU 4902 : Nice boat
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)
题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
随机推荐
- gulp简单使用小记
npm install --save-dev 写入package.json里 var gulp = require('gulp'); var less = require('gulp-less ...
- 字符数组什么时候要加‘\0’
当字符数组以单个字符进行赋值时: char ch[10]; ch[10]={'a','b',---'\0'}; 或者用for循环进行赋值时: for (i=0; i<9; i++){ch[i]= ...
- Android RelativeLayout常用属性介绍
下面介绍一下RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layou ...
- Docker的C/S模式详解
Docker的C/S模式 Docker的C/S模式 Docker Client通过Remote API与Docker Server通信: RESTful风格API STDIN.STDOUT.STDER ...
- IOS版新闻客户端应用源码项目
IOS版新闻客户端应用源码,这个是一款简单的新闻客户端源码,该应用实现没采用任何第三方类库的 ,并且这个应用的UI做得很不错的,值得我们的参考和学习,希望大家可以更加完善这款新闻类的应用吧. 源码下载 ...
- 'gbk' codec can't encode character
做爬虫抓取网页,print(html)进行调试,遇到UnicodeEncodeError: 'gbk' codec can't encode character XX in position XX问题 ...
- 重置出错?微软Win10平板Surface Pro 4重装系统教程详解
重置出错?微软Win10平板Surface Pro 4重装系统教程详解 2015-12-11 15:27:30来源:IT之家作者:凌空责编:凌空 评论:65 Surface Pro 4系统重置出错该怎 ...
- 11417 - GCD
Problem A GCD Input: Standard Input Output: Standard Output Given the value of N, you will have to f ...
- nodejs微信开发获取token,ticket-1
/* jshint -W079 */ /* jshint -W020 */ "use strict"; var _ = require("lodash"); v ...
- How to Type(dp)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...