HDU-3577-------Fast Arrrangement
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的更多相关文章
- HDU 3577 Fast Arrangement (线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...
- HDU - 3577 Fast Arrangement 线段树
Fast Arrangement Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )
线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...
- hdu 3577 Fast Arrangement(线段树区间修改,求区间最小值)
Problem Description Chinese always have the railway tickets problem because of its' huge amount of p ...
- hdu 4965 Fast Matrix Calculation(矩阵高速幂)
题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到 ...
- HDU 4965 Fast Matrix Calculation(矩阵高速幂)
HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个 ...
- HDU 1227 Fast Food
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1227 题意:一维坐标上有n个点,位置已知,选出k(k <= n)个点,使得所有n个点与选定的点中 ...
- hdu 4965 Fast Matrix Calculation
题目链接:hdu 4965,题目大意:给你一个 n*k 的矩阵 A 和一个 k*n 的矩阵 B,定义矩阵 C= A*B,然后矩阵 M= C^(n*n),矩阵中一切元素皆 mod 6,最后求出 M 中所 ...
- [ACM] HDU 1227 Fast Food (经典Dp)
Fast Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 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 ...
随机推荐
- js调用浏览器“打印”与“打印预览”
用到html <object>标签,具体做法如下: 1.在html文档任意位置添加<object>标签: <div style="border: 1px sol ...
- MD5 加盐加密
一.概述 MD5(Message Digest Algorithm 5),是一种散列算法,是不可逆的,即通过md5加密之后没办法得到原文,没有解密算法. 在一般的项目中都会有登录注册功能,最简单的, ...
- 关键路径法(Critical Path Method, CPM)
1.活动节点描述及计算公式 通过分析项目过程中哪个活动序列进度安排的总时差最少来预测项目工期的网络分析. 产生目的:为了解决,在庞大而复杂的项目中,如何合理而有效地组织人力.物力和财力,使之在有限资源 ...
- 类加载器 - ClassLoader详解
获得ClassLoader的途径 获得当前类的ClassLoader clazz.getClassLoader() 获得当前线程上下文的ClassLoader Thread.currentThread ...
- 图解Elasticsearch的核心概念
本文讲解大纲,分8个核心概念讲解说明: NRT Cluster Node Document&Field Index Type Shard Replica Near Realtime(NRT)近 ...
- 红帽学习笔记[RHCE]网络配置与路由转发
目录 网络配置基本的IPV4与IPV6 拓扑图 操作 新加一块网卡 将增加的网卡分别加到两台虚拟机上 在两台虚拟机上配置IPV4与 IPV6 配置域名访问 拓展路由转发 拓扑图 操作 关于网关设置 重 ...
- python2的编码问题小结
对于python2,经常会遇到编码问题,在此小记一下. Python2默认的编码解码方式是ascii码,这点要牢记. windows系统默认是gbk编码的,可以使用chcp查看:936,那就是GBK简 ...
- Kibana创建索引成功,但一直不显示出来(Fielddata is disabled on text fields by default. Set fielddata=true........)
现象 把EFK整个集群搭建完成后,通过Kibana操作界面创建索引(如图1),我创建了lile-zabbix*的索引,显示是创建成功了,但是只要我在重新刷新一次,已经创建的索引就“消失了”.后通过查看 ...
- Spring Security之多次登录失败后账户锁定功能的实现
在上一次写的文章中,为大家说到了如何动态的从数据库加载用户.角色.权限信息,从而实现登录验证及授权.在实际的开发过程中,我们通常会有这样的一个需求:当用户多次登录失败的时候,我们应该将账户锁定,等待一 ...
- 2019-9-23:渗透测试,基础学习,http协议数据包的认识,html css的认识,笔记
Burp suite功能模块Dashboard:扫描Proxy:拦截包,代理 drop:放弃Intruder:爆破Decoder:编码,解码repeater:重放comparer:比较 BP,prox ...