当前位置:网站首页>HDU 4391 Paint The Wall 段树(水
HDU 4391 Paint The Wall 段树(水
2022-07-05 21:39:00 【全栈程序员站长】
大家好,又见面了,我是全栈君
意甲冠军:
特定n多头排列。m操作
以下是各点的颜色
以下m一种操纵:
1 l r col 染色
2 l r col 问间隔col色点
== 通的操作+区间内最大最小颜色数的优化,感觉非常不科学。。。
==感觉能够卡掉这样的写法。。反正就是不科学嘛
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define L(x) tree[x].l
#define R(x) tree[x].r
#define Len(x) tree[x].len
#define Lazy(x) tree[x].lazy
#define M(x) tree[x].minn
#define W(x) tree[x].maxx
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
const int N = 100010;
struct node{
int l, r, len, lazy, minn, maxx;
}tree[N<<2];
int col[N];
void push_up(int id){
if(Lazy(Lson(id)) == Lazy(Rson(id)))
Lazy(id) = Lazy(Lson(id));
else Lazy(id) = -1;
M(id) = min(M(Lson(id)), M(Rson(id)));
W(id) = max(W(Lson(id)), W(Rson(id)));
}
void push_down(int id){
if(Lazy(id) != -1){
Lazy(Lson(id)) = Lazy(Rson(id)) = Lazy(id);
M(Lson(id)) = W(Lson(id)) = Lazy(id);
M(Rson(id)) = W(Rson(id)) = Lazy(id);
}
}
void build(int l, int r, int id){
L(id) = l; R(id) = r;
Len(id) = r-l+1;
Lazy(id) = -1;
if(l == r){
Lazy(id) = col[l];
W(id) = M(id) = col[l];
return ;
}
int mid = (l+r)>>1;
build(l, mid, Lson(id));
build(mid+1, r, Rson(id));
push_up(id);
}
void updata(int l, int r,int val, int id){
if(l == L(id) && R(id) == r){
Lazy(id) = val;
W(id) = M(id) = val;
return ;
}
push_down(id);
int mid = (L(id) + R(id)) >>1;
if(mid < l)
updata(l, r, val, Rson(id));
else if(r <= mid)
updata(l, r, val, Lson(id));
else {
updata(l, mid, val, Lson(id));
updata(mid+1, r, val, Rson(id));
}
push_up(id);
}
int query(int l, int r, int col, int id){
if(!(M(id)<=col && col<=W(id))) return 0;
if(Lazy(id)!=-1){
if(Lazy(id) == col)
return r-l+1;
else return 0;
}
push_down(id);
int mid = (L(id) + R(id)) >>1;
if(mid < l)
return query(l, r, col, Rson(id));
else if(r <= mid)
return query(l, r, col, Lson(id));
else
return query(l, mid, col, Lson(id)) + query(mid+1, r, col, Rson(id));
}
int n, que;
int main() {
while (cin>>n>>que) {
for(int i = 1; i <= n; i++)scanf("%d", &col[i]);
build(1, n, 1);
while(que--){
int type, l, r, color;
scanf("%d %d %d %d", &type, &l, &r, &color);
l++; r++;
if(type == 1)
updata(l, r, color, 1);
else
printf("%d\n", query(l, r, color, 1));
}
}
return 0;
}
/*
5 12
1 2 3 4 0
2 1 3 3
1 1 3 1
2 1 3 3
2 0 3 1
2 3 4 1
1 0 4 0
2 0 4 0
2 0 4 2000000000
1 0 0 1
1 4 4 2
2 0 4 1
2 0 4 2
*/版权声明:本文博客原创文章。博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117563.html原文链接:https://javaforall.cn
边栏推荐
- Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
- 总结出现2xx、3xx、4xx、5xx状态码的原因
- Detailed explanation of memset() function usage
- 1.2 download and installation of the help software rstudio
- Clion configures Visual Studio (MSVC) and JOM multi-core compilation
- Modifiers of attributes of TS public, private, protect
- 【日常训练】729. 我的日程安排表 I
- @Validated基础参数校验、分组参数验证和嵌套参数验证
- 思特奇加入openGauss开源社区,共同推动数据库产业生态发展
- 2.2.5 basic sentences of R language drawing
猜你喜欢

matlab绘制hsv色轮图

How to send samples when applying for BS 476-7 display? Is it the same as the display??

Comprehensive optimization of event R & D workflow | Erda version 2.2 comes as "7"

Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development

JMeter installation under win7

Uni app Bluetooth communication

Reading and writing operations of easyexcel

Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w

Parker driver maintenance COMPAX controller maintenance cpx0200h

R language learning notes
随机推荐
Deployment of Jenkins under win7
kingbaseES V8R3数据安全案例之---审计记录清除案例
EasyExcel的读写操作
Wood board ISO 5660-1 heat release rate mapping test
Kingbasees v8r3 data security case - audit record clearing case
DBeaver同时执行多条insert into报错处理
Pytoch practice -- MNIST dataset handwritten digit recognition
854. 相似度为 K 的字符串 BFS
The primary key is set after the table is created, but auto increment is not set
PVC plastic sheets BS 476-6 determination of flame propagation properties
Defect detection - Halcon surface scratch detection
How to prepare for the algorithm interview and answer the algorithm interview questions
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
Clion configures Visual Studio (MSVC) and JOM multi-core compilation
Four components of logger
matlab绘制hsv色轮图
Establishment of terminal security capability verification environment and penetration test records
Teach yourself to train pytorch model to Caffe (I)
How to send samples when applying for BS 476-7 display? Is it the same as the display??
Longest swing sequence [greedy practice]