博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 3577 Fast Arrangement
阅读量:4982 次
发布时间:2019-06-12

本文共 2720 字,大约阅读时间需要 9 分钟。

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.
InputThe 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.OutputFor 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

13 61 61 63 41 51 22 4

Sample Output

Case 1:1 2 3 5 线段树,每一个区间内的点加一,且不能超过k,注意乘车区间是【l,r-1】.
1 #include
2 #include
3 #include
4 #define ls o<<1 5 #define rs o<<1|1 6 #define lson L,mid,ls 7 #define rson mid+1,R,rs 8 #define middnf int mid=(L+R)>>1; 9 #define ll long long10 11 using namespace std;12 13 const int maxn=1000005; 14 int mx[maxn<<2],lazy[maxn<<2],ou[100005];15 int n,m,x,y,z;16 17 int max(int a,int b)18 {19 return a>b?a:b;20 }21 22 void pushup(int o)23 {24 mx[o]=max(mx[ls],mx[rs]);25 }26 27 void pushdown(int o)28 {29 if(!lazy[o]) return;30 lazy[ls] += lazy[o];31 lazy[rs] += lazy[o];32 mx[ls]+=lazy[o];33 mx[rs]+=lazy[o];34 lazy[o] = 0;35 }36 37 void update(int l,int r,int L,int R,int o,int v){
//区间更新38 if(l<=L&&R<=r)39 {40 mx[o] += v;41 lazy[o] += v;42 return;43 }44 pushdown(o);45 middnf;46 if(l<=mid) update(l,r,lson,v);47 if(r>mid) update(l,r,rson,v);48 pushup(o);49 }50 51 int query(int l,int r,int L,int R,int o)52 {53 if(l<=L&&R<=r) 54 return mx[o];55 pushdown(o);56 middnf;57 int ret = 0;58 if(l<=mid) 59 ret = max(ret,query(l,r,lson));60 if(r>mid) 61 ret = max(ret,query(l,r,rson));62 return ret;63 }64 65 int main()66 {67 char c[5];68 int T,s=0;69 scanf("%d",&T);70 while(T--)71 { 72 int ss=0;73 memset(mx,0,sizeof(mx));74 memset(lazy,0,sizeof(lazy));75 scanf("%d%d",&n,&m);76 for(int i=1;i<=m;i++)77 {78 scanf("%d%d",&x,&y);79 int num=query(x,y-1,1,1000005,1);80 if(num

 

转载于:https://www.cnblogs.com/xibeiw/p/7409788.html

你可能感兴趣的文章
需求分析
查看>>
解决Win7下网络应用只有进程没有界面的问题
查看>>
半监督学习(一)
查看>>
[置顶] SPL讲解(6)--Condition篇
查看>>
在MyEclipse中配置Weblogic10服务器
查看>>
浙江大学PAT上机题解析之2-11. 两个有序链表序列的合并
查看>>
java中equals和==的区别详解
查看>>
数据类型(字符串)
查看>>
Something about Swing
查看>>
设计模式看了又忘,忘了又看?
查看>>
hdu4465 2012 Asia Chengdu Regional Contest 概率期望计算+对数放大/缩小幂指数+对数还原...
查看>>
安装magento主题模板
查看>>
JZOJ.4732 函数
查看>>
Linux:重命名
查看>>
Common Subsequence--poj1458(最长公共子序列)
查看>>
Sql Server2000分页存储过程
查看>>
quagga源码分析--通用库thread
查看>>
TJU_SCS_软件测试_homework1——《error impressed me most》
查看>>
样例功能截图
查看>>
log4j2 Filter用法详解
查看>>