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 ...
随机推荐
- 014.Kubernetes二进制部署docker
一 部署docker 1.1 部署docker组件 docker 运行和管理容器,kubelet 通过 Container Runtime Interface (CRI) 与它进行交互. 1.2 下载 ...
- celery 启用worker ValueError: not enough values to unpack
[2018-01-12 19:08:15,545: INFO/MainProcess] Received task: tasks.add[5d387722-5389-441b-9b01-a619b93 ...
- Ubuntu 18 安装搜狗输入法
Ubuntu 18 安装搜狗输入法: 1. 搜狗输入法官网下载对应的Linux输入法 2. 双击 刚刚下载好的 deb 文件 3. 点击 install(安装) 4. 在 settings(系统设置) ...
- suseoj 1209: 独立任务最优调度问题(动态规划)
1209: 独立任务最优调度问题 时间限制: 1 Sec 内存限制: 128 MB提交: 3 解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 用2台处理机A和B处理 ...
- connected datagram 与TCP连接的区别
TCP连接流程是TCP协议的一部分,需要经过三次握手.而connected datagram虽然使用了socket的同样的函数connect,但是UDP协议并不包含连接流程,也就是UDP实际上并没有真 ...
- vue中自定义html文件的模板
如果默认生成的 HTML 文件不适合需求,可以创建/使用自定义模板. 一是通过 inject 选项,然后传递给定制的 HTML 文件.html-webpack-plugin 将会自动注入所有需要的 C ...
- Install python3
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz tar xf Python-3.7.4.tgz cd Python-3.7. ...
- 线程池的C++实现(一)
现代的软件一般都使用了多线程技术,在有些软件里面,一个线程被创建出来执行了仅仅一个任务,然后就被销毁了.线程的创建与销毁是需要消耗资源,这样为了执行单一任务而被创建出来的线程越多,性能也就越差.如果能 ...
- SQLServer2008R2(百度网盘)下载与安装教程
很久没有安装过这个了,今天安装有点生疏了,这里记录一下分享 分为三块块1.下载地址,2.安装图解 ,3.安装失败问题 1.sqlserver 2008 r2 百度下载地址链接:下载 cn_sql_s ...
- Android 如何动态添加 View 并显示在指定位置。
引子 最近,在做产品的需求的时候,遇到 PM 要求在某个按钮上添加一个新手引导动画,引导用户去点击.作为 RD,我哗啦啦的就写好相关逻辑了.自测完成后,提测,PM Review 效果. 看完后,PM ...