Fast Arrangement

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3563    Accepted Submission(s): 1024


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
 

Author
Louty (Special Thanks Nick Gu)
 

Source
 

Recommend
zhouzeyong

题意:设计一个卖票系统,已经卖出的位置在乘车区间内不能再卖出,输出第几条输入的票可以卖出

思路:用线段树,每卖出一张票就修改指定区间的票数,最后检查总票数即可

#include<cstdio>
#include<cstring>
#define MAXN 1000010
struct node{
int l, r,tag,num;
}tree[MAXN<<2];
int k,q, a, b,cas,len,cnt[MAXN];
int max(int a, int b)
{
return a > b ? a : b;
}
void build(int k, int l, int r)
{
tree[k].tag = 0; tree[k].num = 0;
tree[k].l = l; tree[k].r = r;
if (l == r)
return;
int mid = (l + r) >> 1;
build(k << 1, l, mid);
build(k << 1 | 1, mid + 1, r);
}
void pushup(int k)
{
tree[k].num = max(tree[k << 1].num, tree[k << 1 | 1].num);
}
void pushdown(int k)
{
tree[k << 1].num += tree[k].tag;
tree[k << 1 | 1].num += tree[k].tag;
tree[k << 1].tag += tree[k].tag;
tree[k << 1 | 1].tag += tree[k].tag;
tree[k].tag = 0; }
void update(int k, int l, int r, int x)
{
if (tree[k].l == l&&tree[k].r == r)
{
tree[k].num += x;
tree[k].tag += x;
return;
}
if (tree[k].tag)
pushdown(k);
int mid = (tree[k].l + tree[k].r) >> 1;
if (r <= mid)
update(k << 1, l, r, x);
else if (l >= mid + 1)
update(k << 1 | 1, l, r, x);
else
{
update(k << 1, l, mid, x);
update(k << 1 | 1, mid + 1, r, x);
}
pushup(k);
}
int query(int k, int l, int r)
{ if (tree[k].l == l&&tree[k].r == r)
return tree[k].num;
if (tree[k].tag)
pushdown(k);
int mid = (tree[k].l + tree[k].r) >> 1;
if (r <= mid)
return query(k << 1, l, r);
else if (l >= mid + 1)
return query(k << 1 | 1, l, r);
else
return max(query(k << 1, l, mid) , query(k << 1 | 1, mid + 1, r));
} int main()
{
int t;
cas = 1;
scanf("%d", &t);
while (t--)
{
memset(cnt, 0, sizeof(cnt));
len = 1;
scanf("%d%d", &k, &q);
build(1, 1, 1000010);
for (int i = 1; i <= q; i++)
{
scanf("%d%d", &a, &b);
b--;
if (query(1, a, b) < k)
{
cnt[len++] = i;
update(1, a, b, 1);
}
}
printf("Case %d:\n", cas++);
for (int i = 1; i < len; i++)
{
printf("%d ", cnt[i]);
}
printf("\n\n"); }
return 0;
}

HDU - 3577 Fast Arrangement 线段树的更多相关文章

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

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

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

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

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

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

  4. hdu 5700区间交(线段树)

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  5. Snacks HDU 5692 dfs序列+线段树

    Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...

  6. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

  7. HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  9. HDU 5820 (可持久化线段树)

    Problem Lights (HDU 5820) 题目大意 在一个大小为50000*50000的矩形中,有n个路灯.(n<=500000) 询问是否每一对路灯之间存在一条道路,使得长度为|x1 ...

随机推荐

  1. 【转】c#.net各种应用程序中获取文件路径的方法

    控制台应用程序:Environment.CurrentDirectory.Directory.GetCurrentDirectory() windows服务:Environment.CurrentDi ...

  2. dump函数

    一.函数标准格式: DUMP(expr[,return_fmt[,start_position][,length]]) 基本参数时4个,最少可以填的参数是0个.当完全没有参数时,直接返回null.另外 ...

  3. 64位linux安装32位校园网客户端

    下面的是ubuntu下和arch下的安装方法,ubuntu的转自网络, ubuntu: 下载客户端并解压 安装开发包 1 sudo -i 2 dpkg --add-architecture i386 ...

  4. java后台中处理图片辅助类汇总(上传图片到服务器,从服务器下载图片保存到本地,缩放图片,copy图片,往图片添加水印图片或者文字,生成二维码,删除图片等)

    最近工作中处理小程序宝箱活动,需要java画海报,所以把这块都快百度遍了,记录一下处理的方法,百度博客上面也有不少坑! 获取本地图片路径: String bgPath = Thread.current ...

  5. linux下的usb抓包方法【转】

    转自:http://blog.chinaunix.net/uid-11848011-id-4508834.html 1.配置内核使能usb monitor: make menuconfig       ...

  6. 学习记录:mongodb里插入整型值

    =============================================== 2018/1/24_第1次修改                       ccb_warlock == ...

  7. Python [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 解决方法

    一个搭建在SAE上的Django应用,使用新浪微博提供的Python SDK已经稳定运行一年有余,但最近开始持续出现微博认证失败的状况. 摘录微博python SDK的错误提示如下所示: ERROR: ...

  8. FM的推导原理--推荐系统

    FM:解决稀疏数据下的特征组合问题  Factorization Machine(因子分解机) 美团技术团队的文章,觉得写得很好啊:https://tech.meituan.com/deep-unde ...

  9. elasticsearch文档学习

    1.集群 节点(一个elasticsearch实体)  索引  主节点 :集群级别变更,新增或移除节点,索引:  主节点不参与文档级别搜索和变更. 分片(shard):一个完整的搜索引擎,lucene ...

  10. MySQL学习笔记:definer与sql security

    在以下例子中,出现definer于sql security invoker,导致不解,遂学习一翻. # 创建存储过程 DELIMITER $$ CREATE DEFINER = Hider@local ...