HDU 4391 Paint The Wall 段树(水
意甲冠军:
特定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 */
版权声明:本文博客原创文章。博客,未经同意,不得转载。
HDU 4391 Paint The Wall 段树(水的更多相关文章
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4391 - Paint The Wall - 分块哈希入门
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意 : 给一段区间, 有两种操作 1 : 给 x 到 y 的区间染色为 z 2 : 查询 ...
- HDU 4391 Paint The Wall(分块的区间维护)
题意:给出几个操作,把l-r赋值为z,询问l-r有几个z,其中z < INT_MAX 思路:因为z很大,所以很难直接用线段树去维护.这里可以使用分块来解决.我们可以让每个块用map去储存map[ ...
- HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)
6356.Glad You Came 题意就是给你一个随机生成函数,然后从随机函数里确定查询的左右区间以及要更新的val值.然后最后求一下异或和就可以了. 线段树,区间最大值和最小值维护一下,因为数据 ...
- HDU 5649.DZY Loves Sorting-线段树+二分-当前第k个位置的数
DZY Loves Sorting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- hdu 1754 I Hate It(线段树水题)
>>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...
- hdu 1543 Paint the Wall
http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- hdu - 1394 Minimum Inversion Number(线段树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...
随机推荐
- 4、深入理解Bean
本节知识点: 1. Bean 的自己主动装配(了解) 2. bean 之间的关系:继承:依赖 3.Bean 的作用域:能够在 <bean> 元素的 scope 属性里设置 Bean 的作用 ...
- (1)cocos2d-x-2.2.4搭建windows开发环境
Cocos2d-x-2.2.4搭建windows环境 软件需求 Windows系统(windows7或之后的系统): cocos2d-x-2.2.4压缩包. python安装包(推荐使用2.7.3版本 ...
- 读懂Java中的Socket编程(转)
Socket,又称为套接字,Socket是计算机网络通信的基本的技术之一.如今大多数基于网络的软件,如浏览器,即时通讯工具甚至是P2P下载都是基于Socket实现的.本文会介绍一下基于TCP/IP的S ...
- 收藏的一段关于java大数运算的代码
收藏的一段关于java大数运算的代码: package study_02.number; import java.math.BigDecimal; import java.math.BigIntege ...
- 一些周期性GC的理由为何
1.供tomcat:防止内存泄漏监听器 JreMemoryLeakPreventionListener在上班,每隔一小时默认触发一次System.gc Class clazz = Class.forN ...
- 关于margin-right的应用问题
今天在群里面,有人抛出了一个关于css中margin-right没有效果的问题.CSS代码和HTML代码例如以下: .style1{ width:400px; height:440px; backgr ...
- SWT的TreeVierer的使用
先看一下效果图: 代码结构是这样的: 好的,现在看一下代码: package model; import java.util.List; public interface ITree { public ...
- 可删除超炫&多种特效的Card视图(改造自cardsui-for-android开源项目),提供DEMO下载
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990).谢谢支持! 实例Demo下载地址在本文最后 简介 这个Demo主要是使用了cardsui ...
- java注解(一)
虽然平时有使用注解,不过没有深入了解,今天无聊,重新从基础深入了解整理下: java注解是附加在代码中的一些元信息,用于一些工具在编译.运行时进行解析和使用,起到说明.配置的功能. 注解不会也 ...
- 矩形旋转碰撞,OBB方向包围盒算法实现
怎样进行2D旋转矩形的碰撞检測.能够使用一种叫OBB的检測算法(Oriented bounding box)方向包围盒.这个算法是基于SAT(Separating Axis Theorem)分离轴定律 ...