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 ...
随机推荐
- 访问控制列表ACL
1.ACL Access list ,访问控制列表. 2.作用 限制网络中的地址访问. 3.主要内容 Eg: Router(config)#access-list ? <一>. <1 ...
- ActiveMQ消息队列从入门到实践(1)—JMS的概念和JMS消息模型
1. 面向消息的中间件 1.1 什么是MOM 面向消息的中间件,Message Oriented Middleware,简称MOM,中文简称消息中间件,利用高效可靠的消息传递机制进行平台无关的数据交流 ...
- ChickenLegend Image
- 第一篇:jdk8下载和idea导入,java源码结构
一.下载和导入 下载和导入到idea,完全参考文章:https://blog.csdn.net/zhanglong_4444/article/details/88967300 照做即可,详解简单到位. ...
- nyoj 39-水仙花数
39-水仙花数 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:35 submit:70 题目描述: 请判断一个数是不是水仙花数. 其中水仙花数定义各 ...
- 【前端知识体系-CSS相关】CSS特效实现之Transition和Transform对比
CSS效果 1.使用div绘制图形(三角形)? <!DOCTYPE html> <html lang="en"> <head> <meta ...
- bash:加减乘除(bc、let)
bc *. echo "$2 * $2" | bc > file let 如果只是 let a=1 和 a=1,它们没有区别,但是 let 还可以用于带赋值的运算,例如 le ...
- asp.net Mvc 使用NPOI导出Excel文件
1.新建MVC项目,新建控制器.视图 添加控制器: 添加视图(将使用布局页前面的复选框里的勾勾去掉) 2.在Models里新建一个类 public class Shop { /// <summa ...
- Spring Boot: Spring Doc生成OpenAPI3.0文档
1. 概述 公司正好最近在整理项目的文档,且文档对于构建REST API来说是至关重要的.在这篇文章中,我将介绍Spring Doc , 一个基于OpenAPI 3规范简化了Spring Boot 1 ...
- odoo12 修行基础篇之 添加字段 (一)
本人刚刚接触odoo12,大概有2个多月的时间,这两天有点时间,就集中写下博客. 本来是打算整理成笔记,想到这段时间的开发经历,着实感觉网上有关odoo的资料太少,学习资料也不多,既然与odoo有缘, ...