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.

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 

题解: 把行程的区间用点来衡量 因为在2下车后 也可在2上车  数据太大,在预处理离散化一下即可

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define lowbit(x) (x&(-x))
const int N=1e6+10;
typedef long long ll;
struct node{
	int l,r;
	int laz;
	int maxx;
}tree[N<<2];
struct node1
{
    int l,r;
}a[N];
int k,q,ans[N],cnt,b[N];
void build(int l,int r,int cur)
{
	tree[cur].laz=0;
    tree[cur].maxx=0;
	tree[cur].l=l;
	tree[cur].r=r;
	if(l==r) return;
	int mid=(r+l)>>1;
	build(l,mid,cur<<1);
	build(mid+1,r,cur<<1|1);
}
void pushdown(int cur)
{
    if(tree[cur].laz)
    {
        tree[cur<<1].laz+=tree[cur].laz;
        tree[cur<<1].maxx+=tree[cur].laz;
        tree[cur<<1|1].laz+=tree[cur].laz;
        tree[cur<<1|1].maxx+=tree[cur].laz;
        tree[cur].laz=0;
    }

}
void pushup(int cur)
{
    tree[cur].maxx=max(tree[cur<<1].maxx,tree[cur<<1|1].maxx);
}
int query(int pl,int pr,int cur)
{
    if(pl<=tree[cur].l&&tree[cur].r<=pr)
    {
        return tree[cur].maxx;
    }
    pushdown(cur);
    int res=0;
    if(pl<=tree[cur<<1].r) res=max(res,query(pl,pr,cur<<1));
    if(pr>=tree[cur<<1|1].l) res=max(res,query(pl,pr,cur<<1|1));
    return res;
}
void update(int pl,int pr,int cur)
{
    if(pl<=tree[cur].l&&tree[cur].r<=pr)
    {
        tree[cur].maxx++;
        tree[cur].laz++;
        return;
    }
    pushdown(cur);
    if(pl<=tree[cur<<1].r) update(pl,pr,cur<<1);
    if(pr>=tree[cur<<1|1].l) update(pl,pr,cur<<1|1);
    pushup(cur);
}
int main()
{
	int T,nn=1;
	scanf("%d",&T);
    while(T--)
    {
    	scanf("%d%d",&k,&q);
    	for(int i=1;i<=q;i++) scanf("%d%d",&a[i].l,&a[i].r),b[2*i-1]=a[i].l,b[2*i]=a[i].r;
    	sort(b+1,b+1+2*q);
    	int len=unique(b+1,b+1+2*q)-(b+1);
    	build(1,len,1);
    	cnt=0;
    	for(int i=1;i<=q;i++)
        {
            int l=lower_bound(b+1,b+1+len,a[i].l)-b;
            int r=lower_bound(b+1,b+1+len,a[i].r)-b;
        //    cout<<l<<" "<<r<<endl;
            r--;
            if(query(l,r,1)<k) update(l,r,1),ans[cnt++]=i;
        }
        printf("Case %d:\n",nn++);
        for(int i=0;i<cnt;i++)printf("%d ",ans[i]);
        puts("");
        puts("");
    }
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值