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,判断是否可以乘坐

AC代码为:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1e6+10;
int k,q;

struct node{
int l,r,num,tag;
} tree[maxn<<2];

int max(int a,int b)
{
return a>b? a:b;
}

void build(int k,int l,int r)
{
tree[k].l=l,tree[k].r=r;
tree[k].num=0,tree[k].tag=0;
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].tag+=tree[k].tag;
tree[k<<1|1].tag+=tree[k].tag;
tree[k<<1].num+=tree[k].tag;
tree[k<<1|1].num+=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].r+tree[k].l)>>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,x,y,len=0,flag[maxn],cas=1;
scanf("%d",&t);
while(t--)
{
len=0;
memset(flag,0,sizeof(flag));
scanf("%d%d",&k,&q);
build(1,1,1000000);

for(int i=1;i<=q;i++)
{
scanf("%d%d",&x,&y);
y--;
if(query(1,x,y)<k) 
{
flag[len++]=i;
update(1,x,y,1);
}      
}
printf("Case %d:\n",cas++);
for(int i=0;i<len;i++)
printf("%d ",flag[i]);
printf("\n\n");
}

return 0; 
}

HDU-3577-------Fast Arrrangement的更多相关文章

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

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

  2. HDU - 3577 Fast Arrangement 线段树

    Fast Arrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

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

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

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

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

  5. hdu 4965 Fast Matrix Calculation(矩阵高速幂)

    题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到 ...

  6. HDU 4965 Fast Matrix Calculation(矩阵高速幂)

    HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个 ...

  7. HDU 1227 Fast Food

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1227 题意:一维坐标上有n个点,位置已知,选出k(k <= n)个点,使得所有n个点与选定的点中 ...

  8. hdu 4965 Fast Matrix Calculation

    题目链接:hdu 4965,题目大意:给你一个 n*k 的矩阵 A 和一个 k*n 的矩阵 B,定义矩阵 C= A*B,然后矩阵 M= C^(n*n),矩阵中一切元素皆 mod 6,最后求出 M 中所 ...

  9. [ACM] HDU 1227 Fast Food (经典Dp)

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

  10. HDU - 4965 Fast Matrix Calculation 【矩阵快速幂】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4965 题意 给出两个矩阵 一个A: n * k 一个B: k * n C = A * B M = (A ...

随机推荐

  1. Eclipse对Java项目打Jar包

    在本Java项目中,如下图一所示,Java项目含有外部依赖Jar包 -- fastjson-1.2.29.jar  包. 在经历了多次的失败后,最后我终于使用 Eclipse 对 "Java ...

  2. golang 服务诡异499、504网络故障排查

    事故经过 排查 总结 事故经过 11-01 12:00 中午午饭期间,手机突然收到业务网关非200异常报警,平时也会有一些少量499或者网络抖动问题触发报警,但是很快就会恢复(目前配置的报警阈值是5% ...

  3. haproxy+keepalived练习

    小的网站结构 说明:如果部署在云上,比如阿里云上,不需要自己部署keepalived,直接买阿里云的slb即可,slb然后分发流量到两台haproxy机器 一.先部署两个web服务器 编译安装ngin ...

  4. springboot返回统一接口与统一异常处理

    springboot返回统一接口与统一异常处理 编写人员:yls 编写时间:2019-9-19 0001-springboot返回统一接口与统一异常处理 简介 创建统一的返回格式 Result 封装统 ...

  5. nyoj 813-对决 (i*j == k)

    813-对决 内存限制:64MB 时间限制:1000ms 特判: No 通过数:11 提交数:23 难度:0 题目描述: Topcoder 招进来了 n 个新同学,Yougth计划把这个n个同学分成两 ...

  6. openresty(nginx)中使用lua脚本获取请求IP地址的代码

    人狠话不多,直接上代码:------------------------------------------------------------------------------------- lo ...

  7. 如何编译和使用自定义Qt动态链接库 | how to build and use user-defined qt library

    本文首发于个人博客https://kezunlin.me/post/cf628dd8/,欢迎阅读! guide to build qt library and use in another proje ...

  8. Redis Geo HyperLogLog类型介绍

    ​Geo类型 Redis3.2.0版本推出 可以将用户给定的地理位置信息存储起来,并对这些信息进行操作 GEOADD key longitude latitude member [longitude ...

  9. Linux考题(一)

    1.创建目录/data/oldboy,并且在该目录下创建oldboy.txt,然后在文件oldybos.txt里写入内容“inet addr:192.168.228.128  Bcast:192.16 ...

  10. ArrayList实现原理(JDK1.8)

    ArrayList实现原理(JDK1.8) public class ArrayList<E> extends AbstractList<E> implements List& ...