Problem Description
Chinese always have the railway tickets problem because of its' huge amount of passangers and stations. Now goverment need you to develop a new tickets query system.

One train can just take k passangers. And each passanger can just buy one ticket from station a to station b. Each train cannot take more passangers any time. The one who buy the ticket earlier which can be sold will always get the ticket.
 

Input
The input contains servel test cases. The first line is the case number. In each test case:

The first line contains just one number k( 1 ≤ k ≤ 1000 ) and Q( 1 ≤ Q ≤ 100000 )

The following lines, each line contains two integers a and b, ( 1 ≤ a < b ≤ 1000000 ), indicate a query.

Huge Input, scanf recommanded.
 

Output
For each test case, output three lines:

Output the case number in the first line.

If the ith query can be satisfied, output i. i starting from 1. output an blank-space after each number.

Output a blank line after each test case.
 

Sample Input

1
3 6
1 6
1 6
3 4
1 5
1 2
2 4
 

Sample Output

Case 1:

1 2 3 5

这一题属于成段更新,需要用到lazy思想,题意是每个人按时间顺序从a站坐到b站,然后每趟车不能超过k个人,输出能够坐车的人。这里要注意从a站坐到b站,区间更新的是[a,b-1].这里先用线段树维护4个变量,l,r,max,cnt.l,r表示区间的左右端点,max表示这一段区间的最大人数,cnt表示这段的增量,也是lazy标志。

关于cnt和max怎么进行更新,这是个难的地方,想了很久。每次如果询问区间比当前整段区间小,那么把这整段区间的增量加到左右子树的增量上,然后再把增量加到左右子树的最大值上,最后这段区间的增量变为0.

<pre name="code" class="cpp">#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 1000005
int num,k,a[100005]; int max(int a,int b){
return a>b?a:b;
}
struct node{
int l,r,max,cnt;
}b[4*maxn]; void build(int l,int r,int i)
{
int mid;
b[i].l=l;b[i].r=r;b[i].max=b[i].cnt=0;
if(l==r)return;
mid=(l+r)/2;
build(l,mid,i*2);
build(mid+1,r,i*2+1);
} int question(int l,int r,int i)
{
int mid;
if(b[i].l==l && b[i].r==r){
return b[i].max;
}
if(b[i].cnt){
b[i*2].cnt+=b[i].cnt;b[i*2+1].cnt+=b[i].cnt;
b[i*2].max+=b[i].cnt;b[i*2+1].max+=b[i].cnt;
b[i].cnt=0;
}
mid=(b[i].l+b[i].r)/2;
if(r<=mid)return question(l,r,i*2);
else if(l>mid)return question(l,r,i*2+1);
else return max(question(l,mid,i*2),question(mid+1,r,i*2+1));
} void update(int l,int r,int i)
{
int mid;
if(b[i].l==l && b[i].r==r){
b[i].cnt++;b[i].max++;return;
}
if(b[i].cnt){
b[i*2].cnt+=b[i].cnt;b[i*2+1].cnt+=b[i].cnt;
b[i*2].max+=b[i].cnt;b[i*2+1].max+=b[i].cnt;
b[i].cnt=0;
}
mid=(b[i].l+b[i].r)/2;
if(r<=mid)update(l,r,i*2);
else if(l>mid)update(l,r,i*2+1);
else {
update(l,mid,i*2);
update(mid+1,r,i*2+1);
}
b[i].max=max(b[i*2].max,b[i*2+1].max);
} int main()
{
int m,i,j,T,num1=0,c,d,t;
scanf("%d",&T);
while(T--)
{
num1++;t=0;
printf("Case %d:\n",num1);
scanf("%d%d",&k,&m);
build(1,1000005,1);
memset(a,0,sizeof(a));
for(i=1;i<=m;i++){
scanf("%d%d",&c,&d);
d--;
if(question(c,d,1)<k){
a[++t]=i;
update(c,d,1);
}
}
for(i=1;i<=t;i++){
printf("%d ",a[i]);
}
printf("\n\n");
}
return 0;
}


hdu3577 Fast Arrangement的更多相关文章

  1. HDU - 3577 Fast Arrangement 线段树

    Fast Arrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU 3577 Fast Arrangement (线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...

  3. Fast Arrangement (线段树,延迟标志)

    个人心得:线段树的延迟标志确实是减少了很多时间,思想比较简单,但是实现得时候和建立延迟的时候比较麻烦. 按照我的一些理解,就是更新时找到完全覆盖的区间时,更新延迟标志,不再往下更新,但此时父节点啥的都 ...

  4. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  5. hdu 3577 Fast Arrangement(线段树区间修改,求区间最小值)

    Problem Description Chinese always have the railway tickets problem because of its' huge amount of p ...

  6. HDU 3577Fast Arrangement(线段树模板之区间增减更新 区间求和查询)

    Fast Arrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较

    opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较 参考: http://wenku.baidu.com/link?url=1aDYAJBCrrK-uk2w3sSNai7h52x_ ...

  8. 基于Fast Bilateral Filtering 算法的 High-Dynamic Range(HDR) 图像显示技术。

    一.引言 本人初次接触HDR方面的知识,有描述不正确的地方烦请见谅. 为方便文章描述,引用部分百度中的文章对HDR图像进行简单的描述. 高动态范围图像(High-Dynamic Range,简称HDR ...

  9. Fast RCNN 训练自己的数据集(3训练和检测)

    转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ https://github.com/YihangLou/fas ...

随机推荐

  1. python学习笔记 | wordcloud安装指南

    问题: 直接在命令行输入: pip install wordcloud 不出意外,直接报错,显示缺失vc*****.bat,意思是缺失vc版本,这个安装方式基本可以扔掉. 解决: http://t.c ...

  2. 构造无字母数字Webshell

    异或: 补充: A的ascii为65,对应二进制是01000001 <?php echo "1"^"A"; ?> 将"A"和&q ...

  3. 物理STANDBY库创建还原点(打开为read write后再变回主库)

    开启STANDBY库为READ WRITE 1.取消主库传送归档 SQL> alter system set log_archive_dest_state_2=defer; 2.取消备库应用日志 ...

  4. DockerFile关键字相关作用以及解释

    Dockerfile 关键字 作用 备注 FROM 指定父镜像 指定dockerfile基于那个image构建 MAINTAINER 作者信息 用来标明这个dockerfile谁写的 LABEL 标签 ...

  5. uni-app开发经验分享四: 实现文字复制到选择器中

    这里分享一个我经常用到的一个方法,主要是用来复制文字内容,具体代码如下: var that=this; if(!document){ uni.setClipboardData({ data:复制的值, ...

  6. 深圳某小公司面试题:AQS是什么?公平锁和非公平锁?ReentrantLock?

    AQS总体来说没有想象中那么难,只要了解它的实现框架,那理解起来就不是什么问题了. AQS在Java还是占很重要的地位的,面试也是经常会问. 目前已经连载11篇啦!进度是一周更新两篇,欢迎持续关注 [ ...

  7. 【Android初级】如何动态添加菜单项(附源码+避坑)

    我们平时在开发过程中,为了灵活多变,除了使用静态的菜单,还有动态添加菜单的需求.今天要分享的功能如下: 在界面的右上角有个更多选项,点开后,有两个子菜单:关于和退出 点击"关于", ...

  8. (17)-Python3之--文件操作

    1.文件的操作流程 第一,建立文件对象. 第二,调用文件方法进行操作. 第三,不要忘了关闭文件.(文件不关闭的情况下,内容会放在缓存,虽然Python会在最后自动把内容读到磁盘,但为了以防万一,要养成 ...

  9. 自监督SOTA框架 | BYOL(优雅而简洁) | 2020

    文章原创自微信公众号「机器学习炼丹术」 作者:炼丹兄 联系方式:微信cyx645016617 本篇文章主要讲解两个无监督2020年比较新比较火的论文: 论文名称:"Bootstrap You ...

  10. 前序遍历 排序 二叉搜索树 递归函数的数学定义 return 递归函数不能定义为内联函数 f(x0)由f(f(x0))决定

    遍历二叉树   traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化 1. 二叉树3个基本单元组成:根节点.左子树.右子树 以L.D.R ...