Fast Arrangement

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

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   |   We have carefully selected several similar problems for you:  3578 2795 3581 1166 1698 

题目意思:
现在有一辆列车,可以坐k个人
先买到票的就有座位
现在给你q个买票问询:a站到b站
如果此票持有者路上车,则输出问询编号
线段树解决
如果此时a,b区间内最大值是小于k的,那么
说明此人可以上车
可以上车的话
将区间a,b内部的值加1
完全符合线段树的基本操作
区间更新 区间增减
区间查询 找最值
#include<stdio.h>
#include<iostream>
#include<vector>
#include <cstring>
#include <stack>
#include <cstdio>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include<string>
#include<math.h>
using namespace std;
const int max_v=;
int ans[max_v];
struct node
{
int l,r,v,lazy;
}tree[max_v<<];
void build(int l,int r,int root)
{
tree[root].l=l;
tree[root].r=r;
tree[root].v=;
tree[root].lazy=; if(l==r)
return ; int mid=(l+r)>>;
build(l,mid,root<<);
build(mid+,r,root<<|);
}
void push_up(int root)//往上更新父节点数据
{
tree[root].v=max(tree[root<<].v,tree[root<<|].v);// 最值
}
void push_down(int root)//向下往左右儿子方向更新数据
{
tree[root<<].lazy+=tree[root].lazy;
tree[root<<|].lazy+=tree[root].lazy; tree[root<<].v+=tree[root].lazy;
tree[root<<|].v+=tree[root].lazy; tree[root].lazy=;//更新之后lazy清零
}
void update(int l,int r,int root)
{
if(tree[root].l==l&&tree[root].r==r)//如果区间完全重合,则不需要继续往下更新了
{
tree[root].v+=;
tree[root].lazy+=;
return;
}
if(tree[root].lazy)//因为没有找到完全重合的区间,所以要先更新下一层区间;
push_down(root); int mid=(tree[root].l+tree[root].r)>>;
if(l>mid)
update(l,r,root<<|);
else if(r<=mid)
update(l,r,root<<);
else
{
update(l,mid,root<<);
update(mid+,r,root<<|);
} push_up(root);//最后还得往上面更新父节点区间
}
int getmax(int l,int r,int root)//查询区间最值
{
if(tree[root].l==l&&tree[root].r==r)
return tree[root].v; if(tree[root].lazy)//因为没有找到完全重合的区间,所以要先更新下一层区间
push_down(root); int mid=(tree[root].l+tree[root].r)>>;
if(l>mid)
return getmax(l,r,root<<|);
else if(r<=mid)
return getmax(l,r,root<<);
else
{
return max(getmax(l,mid,root<<),getmax(mid+,r,root<<|));
}
}
int main()
{
int t;
scanf("%d",&t);
int c=;
while(t--)
{
memset(ans,,sizeof(ans));
int k,q;
scanf("%d %d",&k,&q);
build(,,);
int m=;
for(int i=;i<q;i++)
{
int a,b;
scanf("%d %d",&a,&b);
b--;
if(getmax(a,b,)<k)
{
ans[m++]=i+;
update(a,b,);
}
}
printf("Case %d:\n",c++);
for(int i=;i<m;i++)
printf("%d ",ans[i]);
printf("\n\n");
}
return ;
}
/*
题目意思:
现在有一辆列车,可以坐k个人
先买到票的就有座位
现在给你q个买票问询:a站到b站
如果此票持有者路上车,则输出问询编号
线段树解决
如果此时a,b区间内最大值是小于k的,那么
说明此人可以上车
可以上车的话
将区间a,b内部的值加1 完全符合线段树的基本操作
区间更新 区间增减
区间查询 找最值
*/

HDU 3577Fast Arrangement(线段树模板之区间增减更新 区间求和查询)的更多相关文章

  1. POJ 3468 A Simple Problem with Integers(线段树模板之区间增减更新 区间求和查询)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 140120 ...

  2. POJ 2155 Matrix (二维线段树入门,成段更新,单点查询 / 二维树状数组,区间更新,单点查询)

    题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn ...

  3. HDU(1166),线段树模板,单点更新,区间总和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 第一次做线段树,帆哥的一句话,我记下来了,其实,线段树就是一种处理数据查询和更新的手段. 然后, ...

  4. HDU 1698 Just a Hook (线段树模板题-区间求和)

    Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...

  5. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

  6. hdu1754 I hate it线段树模板 区间最值查询

    题目链接:这道题是线段树,树状数组最基础的问题 两种分类方式:按照更新对象和查询对象 单点更新,区间查询; 区间更新,单点查询; 按照整体维护的对象: 维护前缀和; 维护区间最值. 线段树模板代码 # ...

  7. 线段树:Segment Tree(单点修改/区间修改模板) C++

    线段树是非常有效的数据结构,可以快速的维护单点修改,区域修改,查询最大值,最小值等功能. 同时,它也很重要.如果有一天比赛,你卡在了一道线段树模板题目上,这就真的尴尬了.不过,随着时代的进步,题目也越 ...

  8. hdu 4031 attack 线段树区间更新

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

  9. HDU 1754:I Hate It(线段树模板)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. SpringMVC作用、SpringMVC核心组件、创建项目流程

    SpringMVC框架 1. 作用 解决了V-C的交互问题,即视图与控制器的交互问题. 在原生的Java EE技术中,使用Servlet作为项目中的控制器,用于接收用户的请求,并给予响应结果.这种做法 ...

  2. Task15 节点层次笔记

    childElementCount : 返回子元素的个数 (不包括文本节点和注释节点) children:返回指定元素的子元素集合,它只返回HTML节点,甚至不返回文本节点,虽然不是标准的DOM属性, ...

  3. 关于HSTS的总结

    访问http网站,和服务器交互的步骤浏览器向服务器发起一次HTTP请求服务器返回一个重定向地址浏览器在发送一次HTTPS请求,得到最终内容 上面浏览器发送http请求后容易被拦截,使用HSTS后可以避 ...

  4. Tab Key not working when using Xfce remote desktop

    Xfce 远程桌面Tab键设置 Use CTRL-tab instead of  tab The XFCE Terminal has kidnapped the tab key for a featu ...

  5. House of Roman 实战

    前言 这是前几天国外一个 老哥 提出的一种思路 ,学习了一下感觉其中的堆布局的手法还不错,做个分享与记录. 这种利用手法的主要特点是不需要 leak libc的地址,通过 堆内存的布局 和 堆相关的漏 ...

  6. paramiko的安装与使用

    paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接,支持在远程登录服务器执行命令和上传下载文件的功能. 安装 pycrypto下载地址: ...

  7. hyper-v 无线网连接

    本人的工作环境 笔记本一台,window 10系统64位.平时连接的是有线网,今天回到家里,准备继续在Hyper-v虚拟机上进行操作,发现不能连网,自己立马想到了是不是没有虚拟机上没有和主机共享无线网 ...

  8. 使用Reflector反编译并提取源代码

    Reflector是一个强大的.net 反编译工具,有时我们不止需要反编译源代码,更需要提取源代码. Reflector本身不自带提取源代码功能,不过可以借助插件Reflector.FileDisas ...

  9. MongoDB 安装和使用问题总结

    1. 一直安装不了[一直next下去但最后没有发现生成文件夹] 去掉 Installing MongoDB Compass 前面的打勾 2. 需要开两个cmd运行mongodb 开第一个,输入以下运行 ...

  10. GBK与UTF-8编码错误转换后,无法再正确恢复

    字符集错误转换导致的问题 UTF-8格式编码的字节流,按GBK字符集转换为字符串,会出现乱码,这很正常.但将其重新转为字节流,再用UTF-8字符集转为字符串,还是乱码.这就让我产生了疑惑,虽然使用错误 ...