ural1424 Minibus
Minibus
Memory limit: 64 MB
Background
Problem
Input
Output
Sample
input | output |
---|---|
6 2 6 9 |
36 |
分析:贪心+线段树;
按结束时间排序,则尽可能让座位坐满,线段树区间更新判断是否可坐;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
vi ans;
struct node
{
int x,y,id;
bool operator<(const node&p)const
{
return y<p.y;
}
}a[maxn];
struct Node
{
int Max, lazy;
} T[maxn<<]; void PushUp(int rt)
{
T[rt].Max = max(T[rt<<].Max, T[rt<<|].Max);
} void PushDown(int L, int R, int rt)
{
int mid = (L + R) >> ;
int t = T[rt].lazy;
T[rt<<].Max += t;
T[rt<<|].Max += t;
T[rt<<].lazy += t;
T[rt<<|].lazy += t;
T[rt].lazy = ;
} void Update(int l, int r, int v, int L, int R, int rt)
{
if(l==L && r==R)
{
T[rt].lazy += v;
T[rt].Max += v;
return ;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) Update(l, r, v, Lson);
else if(l > mid) Update(l, r, v, Rson);
else
{
Update(l, mid, v, Lson);
Update(mid+, r, v, Rson);
}
PushUp(rt);
} int Query(int l, int r, int L, int R, int rt)
{
if(l==L && r== R)
{
return T[rt].Max;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) return Query(l, r, Lson);
else if(l > mid) return Query(l, r, Rson);
return max(Query(l, mid, Lson) , Query(mid + , r, Rson));
}
int main()
{
int i,j;
scanf("%d%d%d%d",&n,&m,&k,&t);
rep(i,,k)scanf("%d%d",&a[i].x,&a[i].y),a[i].id=i;
sort(a+,a+k+);
rep(i,,k)
{
if(Query(a[i].x,a[i].y-,,n,)<m)
{
ans.pb(a[i].id);
Update(a[i].x,a[i].y-,,,n,);
}
}
printf("%lld\n",(ll)ans.size()*t);
if(ans.size())printf("%d",ans[]);
for(i=;i<ans.size();i++)printf(" %d",ans[i]);
printf("\n");
//system("Pause");
return ;
}
ural1424 Minibus的更多相关文章
- English word
第一部分 通过词缀认识单词 (常用前缀一) 1.a- ①加在单词(形容词)或词根前面,表示"不,无,非" acentric [ə'sentrik] a 无中心的(a+centr ...
- UVA12653 Buses
Problem HBusesFile: buses.[c|cpp|java]Programming competitions usually require infrastructure and or ...
- TensorFlow和最近发布的slim
笔者将和大家分享一个结合了TensorFlow和最近发布的slim库的小应用,来实现图像分类.图像标注以及图像分割的任务,围绕着slim展开,包括其理论知识和应用场景. 之前自己尝试过许多其它的库,比 ...
- e-olymp Problem8352 Taxi
作为我在这个OJ玩了一下午的终结吧. 水题一道,阅读理解OJ. 传送门:点我 Taxi At the peak hour, three taxi buses drove up at the same ...
- 微信emoji的code
const MAP = [ "\xc2\xa9" => 'COPYRIGHT SIGN', "\xc2\xae" => ...
- Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题
B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...
- github提交表情包
emoji-list emoji表情列表 目录 人物 自然 事物 地点 符号 人物 :bowtie: :bowtie: :smile: :smile: :laughing: :laughing: :b ...
- Preparing Cities for Robot Cars【城市准备迎接自动驾驶汽车】
Preparing Cities for Robot Cars The possibility of self-driving robot cars has often seemed like a f ...
- BEC listen and translation exercise 42
These were built for the workers towards the end of the eighteenth century, and they are still furni ...
随机推荐
- C中内存分配方式[转载]
在C 中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储区. 一.简介: 1.栈,就是那些由编译器在需要的时候分配,在无需的时候自动清除的变量的存储区.里面的变量通常是局部变 ...
- PHP signal 信号
最早写php时,发现在终端执行一个php文件,会一直等待程序执行完成以后,终端才能继续下面的操作,若不小心按了下Ctrl+C会导致php程序退出,闭避免这种情况发生,将会使用php的系统编程,即sig ...
- 手把手教你ranorex_android自动化测试第一个示例
要说android的自动化,那真是折腾死我了,从早期的monkeyrunner,到后来的robotium,再到最新的uiautomator,各有各的问题,总之性价比都不够高,不太适合我的使用场景.于是 ...
- Internet History, Technology and Security (Week1)
Week1. History: Dawn of Electronic Computing War Time Computing and Conmmunication Keywords: Electro ...
- JavaScript高级程序设计:第六章
第六章 面向对象的程序设计 一.理解对象 1.属性类型: ECMAScript中有两种属性:数据属性和访问器属性. (1)数据属性: 数据属性包含一个数据值的位置.在这个位置可以读取和写入值.数据属性 ...
- myeclipse复制项目
一.myEclipse 复制后修改名称,访问不到项目 这是因为,你只是改了项目的名称,而没有改 下面是解决方法: 方法 1.右击你的项目,选择"properties",在" ...
- CentOS 7 BIND 主从搭建
主机 10.2.0.15 从机 10.2.0.14 1 主机配置$vim /etc/named.bodani.com.zones zone"bodani.com" IN { typ ...
- vi 使用教程
编辑一个文本文件是经常使用到的计算机操作.我们想做的大多数事情都需要使用某种文件编辑.文本编辑器会方便文件的创建和修改.编辑一个文本文件是经常使用到的计算机操作.我们想做的大多数事情都需要使用某种文件 ...
- tableView滚动的时候会 最后一行显示不完全的问题
问题可能原因 1:tableView高度的设置不正确,应该是屏幕的高度减去上面的高度(包括状态栏以及navigationBar的高度).正确设置了tableView的高度之后,才可以正常滚动到最后一行 ...
- Hibernate 关系映射方式(1)
来源:本文转载自:http://blog.csdn.net/huangaigang6688/article/details/7761310 Hibernate映射解析——七种映射关系 首先我们了解一个 ...