CF1260D A Game with Traps
http://codeforces.com/problemset/problem/1260/D
首先很明显可以想到二分答案,把能力值数组排个序就好。
考虑怎么check。
设当前二分值为w,即不能直接跨过权值>w的陷阱。
将所有的陷阱按l升序排列。可以发现,如果两个或多个
陷阱重叠,肯定是这个人直接从这几个陷阱最小的l走到
最大的r最优。
证明?这里只给出两个区间重叠的情况。
假设两个区间分别为[a,b],[c,d],a<c<b<d。
想把队伍从a带到d,第一种的总时间为3(d-a);如果是a->c
->a->b->d->c->d,总耗时是3(c-a)+3(d-b)-(c-b)
=3d+2c-2b-3a>3d-3a。
用双指针模拟就好。
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
#define I inline void
#define IN inline int
typedef long long ll;
I read(int &res){
re g=1;register char ch=getchar();res=0;
while(!isdigit(ch)){
if(ch=='-')g=-1;
ch=getchar();
}
while(isdigit(ch)){
res=(res<<3)+(res<<1)+(ch^48);
ch=getchar();
}
res*=g;
}
int n,m,k,t,p,q,X,Y,sum,lim,a[202000];
inline bool bbb(int x,int y){
return x>y;
}
struct Barrier{
int l,r,w;
friend bool operator < (Barrier x,Barrier y){
return x.l==y.l?x.r<y.r:x.l<y.l;
}
}b[202000];
IN ck(int x){
if(!x)return 1;
sum=0;
lim=a[x];
p=1;
while(p<=k&&b[p].w<=lim)p++;
if(p>k)X=sum=0;
else sum=X=b[p].l-1;
while(p<=k){
Y=b[p].r;
q=p+1;
while(q<=k&&(b[q].w<=lim||b[q].l<=Y)){
if(b[q].w>lim)Y=max(Y,b[q].r);
q++;
}
sum+=3*(Y-X);
X=Y;
if(q>k)break;
sum+=(b[q].l-1-X);
X=b[q].l-1;
p=q;
}
sum+=(m-X);
//cout<<x<<" "<<sum<<endl;
if(sum<=t)return 1;
return 0;
}
IN divided(int x,int y){
if(x==y)return x;
re mid=(x+y+1)>>1;
if(ck(mid))x=mid;
else y=mid-1;
return divided(x,y);
}
int main(){
read(n);read(m);read(k);read(t);m++;
F(i,1,n){
read(a[i]);
}
sort(a+1,a+1+n,bbb);
F(i,1,k){
read(b[i].l);read(b[i].r);read(b[i].w);
}
sort(b+1,b+1+k);
b[k+1].l=0;
if(m>t){
cout<<"0";
return 0;
}
cout<<divided(0,n);
return 0;
}
CF1260D A Game with Traps的更多相关文章
- [转]50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs
http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/ 50 Shades of Go: Traps, Gotc ...
- 绕过PALOALTO TRAPS EDR解决方案
0x1 技术点 PaloAlto Traps(EDR解决方案)基于行为封锁和标记许多黑客工具. 0x2 绕过方法 最简单的解决方案就是禁用内置实用程序,即; Cytool.Cytool是一个集成命令行 ...
- C Traps:运算
位移 如果sizeof(int) = 4,那么下面的代码的结果是什么? int x=255; printf("%d", x>>34); 实际输出:63 在编译这个代码时 ...
- C Traps:优先级常见错误
逻辑与关系运算符 if (flags & FLAG != 0) {...} 这类错误以前也犯过,因为!=的优先级比&要高所以实际上是这样的 if (flags & (FLAG ...
- [转载] C 陷阱与缺陷( C traps and Pitfalls )
本文转自 https://www.xuebuyuan.com/1951579.html 自己找工作过程中复习过的书包括<C traps and Pitfalls>,<编程珠玑> ...
- <C Traps and Pitfalls>笔记
//------------------------------------------------------------------------------ 2.1 理解函数的声明: 编写一个独立 ...
- 【C traps and pit falls】阅读笔记
已经是第几遍读C 陷阱与缺陷了,某种意义上,这不是一本常读常新的书,大概是因为读一遍过后就记住了. 一.编译器在将程序分解成符号的时候,使用的是大嘴法. 二.使用不对称边界有很多好处. 三.缓冲输出与 ...
- Python Tips and Traps(二)
6.collections 模块还提供有OrderedDict,用于获取有序字典 import collections d = {'b':3, 'a':1,'x':4 ,'z':2} dd = col ...
- Python Tips and Traps(一)
1.如果想得到一个列表的index和内容,可以通过enumerate快速实现 drinks = ['coffee','tea', 'milk', 'water'] for index, drink i ...
随机推荐
- SSH——ssh_exchange_identification: read: Connection reset by peer
前言 ssh远程连接出错 步骤 查看ssh的详细信息 [root@pre-nginx02 ~]# ssh -v 192.168.1.164 OpenSSH_6.6.1, OpenSSL 1.0.1e- ...
- GITHUB常见命令
1 常用 $ git remote add origin git@github.com:yeszao/dofiler.git # 配置远程git版本库 $ git pull origin master ...
- Codeforces 1251E Voting
E2. Voting (Hard Version) 题意: 有n个人, 你想让他们都给你投票. 你可以选择花费pi收买第i个人, 或者如果有mi个人已经给你投票了, 那么第i个人会自动给你投票. 不妨 ...
- Evaluation of fast-convergence algorithm for ICA-based blind source separation of real convolutive mixture
实际卷积混合情况下,基于ICA的盲源分离算法快速收敛性能评估[1]. 提出了一种新的盲源分离算法,该算法将独立分量分析ICA和波束形成BF相结合,通过优化算法来解决盲源分离的低收敛问题.该方法由以下三 ...
- Support Vector Machines
支持向量机SVM. 简介 SVM核函数包括线性核函数.多项式核函数.径向基核函数.高斯核函数.幂指数核函数.拉普拉斯核函数.ANOVA核函数.二次有理核函数.多元二次核函数.逆多元二次核函数以及Sig ...
- width: calc(100% - 80px); 屏幕自适应方法
width: calc(100% - 80px); 屏幕自适应方法
- tldr/cheat
tldr 比man好用的查询命令查询工具, man很强大,但是 TLDR,too long dont read 安装 npm install -g tldr 使用说明 其他版本下载 https://g ...
- 数据结构实验之排序四:寻找大富翁(SDUT 3401)
#include <stdio.h> #include <stdlib.h> #include <string.h> void Swap(int a[], int ...
- allure-pytest 测试报告分享给大家
allure-pytest生成测试报告,经过实践得出如下经验,参考了很多大神的博客一并附上 1.安装allure-pytest pip install allure-pytest 2.执行命令生成js ...
- java JBDC操作
类似:c# 里面的ado.net 增删改查,动手做Demo (当然实际企业开发很少用这种方式 ). ps:以前从一开始 搞ssm spring Boot spring Mvc 什么都懂一点.什么都 ...