HDU3577 线段树(区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 ,普通的线段树区间更新题目,较简单。
相当于一个区间覆盖问题,有一点要注意的就是叶子节点是一个长度为1的区间,而不是一个离散的点,两种叶子节点的具体区别我在这篇博客里提到过。
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL __int64
#define eps 1e-8
#define INF INT_MAX
#define lson l , m , rt << 1
#define rson m , r , rt << 1 | 1
const int MOD = ;
const int maxn = + ;
const int N = + ;
int cnt[maxn << ] , col[maxn << ];
int ans[N];
void build()
{
memset(cnt , , sizeof(cnt));
memset(ans , , sizeof(ans));
memset(col , , sizeof(col));
}
void PushUp(int rt)
{
cnt[rt] = max(cnt[rt << ] , cnt[rt << | ]);
}
void PushDown(int rt)
{
if(col[rt]) {
col[rt << ] += col[rt];
col[rt << | ] += col[rt];
cnt[rt << ] += col[rt];
cnt[rt << | ] += col[rt];
col[rt] = ;
}
}
void update(int L , int R , int l , int r , int rt)
{
if(L <= l && R >= r) {
cnt[rt]++;
col[rt]++;
return;
}
PushDown(rt);
int m = (l + r) >> ;
if(L >= m)
update(L , R , rson);
else if(R <= m)
update(L , R , lson);
else {
update(L , R , lson);
update(L , R , rson);
}
PushUp(rt);
}
bool query(int L , int R , int k , int l , int r , int rt)
{
if(L <= l && R >= r) {
return cnt[rt] < k;
}
PushDown(rt);
int m = (l + r) >> ;
if(L >= m)
return query(L , R , k , rson);
else if(R <= m)
return query(L , R , k , lson);
else
return query(L , R , k , lson) && query(L , R , k , rson);
}
int main()
{
int T , i , n , m , k , a , b;
cin >> T;
for(int j = ; j <= T ; j++)
{
build();
scanf("%d %d" , &k , &m);
for(i = ; i <= m ; i++) {
scanf("%d %d" , &a , &b);
if(query(a , b , k , , maxn , )) {
update(a , b , , maxn , );
ans[i]++;
}
}
printf("Case %d:\n" , j);
for(i = ; i <= m ; i++)
if(ans[i])
printf("%d " , i);
printf("\n\n");
}
return ;
}
提供几组测试数据:
4
3 6
1 6
1 6
3 4
1 5
1 2
2 4
3 10
2 4
4 6
6 8
2 8
1 8
1 2
1 10
2 9
3 7
9 10
3 10
4 5
5 6
6 7
7 8
9 10
1 4
1 10
2 9
4 6
3 8
3 8
4 6
6 8
9 10
1 4
1 10
2 9
4 6
3 8
Case 1:
1 2 3 5
Case 2:
1 2 3 4 5 6 10
Case 3:
1 2 3 4 5 6 7 8
Case 4:
1 2 3 4 5 6
HDU3577 线段树(区间更新)的更多相关文章
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新
#1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- HDU5039--Hilarity DFS序+线段树区间更新 14年北京网络赛
题意:n个点的树,每个条边权值为0或者1, q次操作 Q 路径边权抑或和为1的点对数, (u, v)(v, u)算2个. M i修改第i条边的权值 如果是0则变成1, 否则变成0 作法: 我们可以求出 ...
随机推荐
- ASP.NET jquery 获取服务器控件ID
一般方法: jQuery("#txtUserName").val(); 如果页面加载了母版页或者自定义控件:该页面的ID有可能会被篡改(可能是因为避免控件ID冲突的机制),因此强烈 ...
- C# - char类型的一些介绍
Char C#里面的char,其实就是System.Char类型的别名,它代表一个Unicode字符(是这样吗?),占用两个字节. 例如:char c = ‘A’; char占用两个字节,也就是16位 ...
- 图像的读取,显示与保存(基于skimage模块)
一 skiamge模块 skimage包的全称是scikit-image SciKit (toolkit for SciPy) ,它对scipy.ndimage进行了扩展,提供了更多的图片处理功能.它 ...
- 5.Python初窥门径(字典)
Python字典学习 1.字典初识 1.字典的简单介绍 字典(dict),是python中唯一的映射类型.他是以{ }括起来的键值对组成.在dict中key是唯一的.在保存的时候,根据key来 ...
- Ubuntu 防火墙IP转发做NAT,内网集群共享网络(简单)
服务器架构: 系统: Ubuntu 16.04 x64 使用自带防火墙 UFW 操作: 在有公网的服务器上,进行防火墙基本操作开启自己所需业务的端口,并按下方设置启动NAT: 其他内网机器修改网关或者 ...
- 关于Git的一些操作记录
本文是我的一些记录,不按教学顺序 1.如何添加不上传的文件或文件夹,并且将已经添加到远程库的文件夹删除 操作过程如下: vim .gitignore // 按i进入编辑模式 写入 node_modul ...
- :input获得焦点时被弹出键盘挡住解决办法
这个是移动端非常常见的bug了,这里说下综合的解决办法,因为有时候你的办法就是会失效.. 上代码 /*input框调起输入法盖住输入问题*/$('input[type="text" ...
- Windows Server 2016 安装Docker
使用Windows自带的Hyper-V 而不是安装Docker Enterprise. 废话不多说,撸起袖子开干 管理员权限打开PowerShell (因为server版本默认是cmd不是ps,所以需 ...
- HDU 5763 Another Meaning dp+字符串hash || DP+KMP
题意:给定一个句子str,和一个单词sub,这个单词sub可以翻译成两种不同的意思,问这个句子一共能翻译成多少种不能的意思 例如:str:hehehe sub:hehe 那么,有**he.he** ...
- OpenStack Cirros
Cirros Openstack的开发,基本都使用这个image来测试,因为他比较小,只有10M. 镜像介绍 镜像的地址: https://launchpad.net/cirros/trunk/0.3 ...