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 作法: 我们可以求出 ...
随机推荐
- 洛谷P1772 [ZJOI2006]物流运输
P1772 [ZJOI2006]物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线 ...
- 洛谷P1065 作业调度方案
P1065 作业调度方案 题目描述 我们现在要利用m台机器加工n个工件,每个工件都有m道工序,每道工序都在不同的指定的机器上完成.每个工件的每道工序都有指定的加工时间. 每个工件的每个工序称为一个操作 ...
- MCP|XHK|High-density peptide arrays help to identify linear immunogenic B cell epitopes in individuals naturally exposed to malaria infection(高密度肽段阵列有助于在自然暴露于疟疾感染的个体中识别线性免疫原性B细胞表位)
文献名:High-density peptide arrays help to identify linear immunogenic B cell epitopes in individuals n ...
- Python中print()函数不换行的方法
一.让print()函数不换行 在Python中,print()函数默认是换行的.但是,在很多情况下,我们需要不换行的输出(比如在算法竞赛中).那么,在Python中如何做到这一点呢? 其实很简单.只 ...
- spring boot 使用WebSocket与前端进行byte字节数组交互
一.装逼前先热热身 无论是比较传统的 web项目 还是近几年流行的前后端分离,后端只独立提供数据交互接口服务的项目,都避免不了数据之间交互格式的选择. 从很早之前的 xml 格式 到现在最火热的jso ...
- ORACLE 12.1.0.1 至12.1.0.2升级文档(单机版 DBUA方式)
12C DBUA新特性 1. 新的pre-upgrade 检查工具. 2. 并行升级. 3. DBUA升级时,默认并行度为CPU个数或2. 并行度可调整. 4. 在升级过程中,DBUA工具可再次调用( ...
- AngularJs1.X学习--路由
[三种使用说明:] $stateProvider.state('station.printQRCode', { //params: { 'parentOfficeId': null }, //一次性参 ...
- 得到RequestVO
import java.io.IOException; import java.nio.charset.Charset; import javax.servlet.ServletInputStream ...
- Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告2(使用PyCharm )
1.说明 在我前一篇文件(Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告1(使用IDLE ))中简单的写明了,如何生产测试报告,但是使用IDLE很麻烦, ...
- postgresql删除还有活动连接的数据库
select pg_terminate_backend(pid) from pg_stat_activity where datname='testdb' and pid<>pg_back ...