HDU - 3577 Fast Arrangement
Posted 西北会法语
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 3577 Fast Arrangement相关的知识,希望对你有一定的参考价值。
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
1 3 6 1 6 1 6 3 4 1 5 1 2 2 4
Sample Output
Case 1: 1 2 3 5
线段树,每一个区间内的点加一,且不能超过k,注意乘车区间是【l,r-1】.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 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 long 10 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<n) 81 { 82 ou[ss++]=i; 83 update(x,y-1,1,1000005,1,1); 84 } 85 } 86 printf("Case %d:\n",++s); 87 for(int i=0;i<ss;i++) 88 { 89 printf("%d ",ou[i]); 90 } 91 printf("\n\n"); 92 } 93 94 95 return 0; 96 }
以上是关于HDU - 3577 Fast Arrangement的主要内容,如果未能解决你的问题,请参考以下文章
HDU 3577 Fast Arrangement (线段树区间更新)
HDU 4965 Fast Matrix Calculation(矩阵高速幂)