BZOJ4223 : Tourists
将位置划分成$O(m)$段区间,每段最早被阻挡的时间可以用堆维护。
那么每段区间对询问的贡献独立,扫描线处理即可。
时间复杂度$O(m\log m)$。
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int>P;
const int N=100010;
int n,m,i,x,y,z,cnt,tot,sum,k;bool del[N];priority_queue<P>q;
struct E{int x,y,p;E(){}E(int _x,int _y,int _p){x=_x,y=_y,p=_p;}}e[N<<1],a[N<<2];
inline bool cmp(const E&a,const E&b){return a.x<b.x;}
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
inline void add(int x,int y){
while(!q.empty())if(del[q.top().second])q.pop();else break;
if(q.empty())return;
int t=-q.top().first;
a[++tot]=E(t-y,y-t,1);
a[++tot]=E(t-x,t-x,-1);
}
int main(){
read(m),read(n);
for(i=1;i<=n;i++){
read(x),read(y),read(z);
e[++cnt]=E(x,z,i);
e[++cnt]=E(y,z,-i);
}
sort(e+1,e+cnt+1,cmp);
for(i=1;i<=cnt;i++){
if(i>1&&e[i].x>e[i-1].x)add(e[i-1].x,e[i].x);
if(e[i].p>0)q.push(P(-e[i].y,e[i].p));else del[-e[i].p]=1;
}
sort(a+1,a+tot+1,cmp);
for(i=1;m--;printf("%d\n",x*k+sum))for(read(x);i<=tot&&a[i].x<=x;i++)sum+=a[i].y,k+=a[i].p;
return 0;
}
BZOJ4223 : Tourists的更多相关文章
- 【Codefoces487E/UOJ#30】Tourists Tarjan 点双连通分量 + 树链剖分
E. Tourists time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard inpu ...
- Tourists
Tourists 时间限制: 5 Sec 内存限制: 64 MB 题目描述 In Tree City, there are n tourist attractions uniquely labele ...
- CF487 E. Tourists [点双连通分量 树链剖分 割点]
E. Tourists 题意: 无向连通图 C a w: 表示 a 城市的纪念品售价变成 w. A a b: 表示有一个游客要从 a 城市到 b 城市,你要回答在所有他的旅行路径中最低售价的最低可能值 ...
- 【CF487E】Tourists(圆方树)
[CF487E]Tourists(圆方树) 题面 UOJ 题解 首先我们不考虑修改,再来想想这道题目. 我们既然要求的是最小值,那么,在经过一个点双的时候,走的一定是具有较小权值的那一侧. 所以说,我 ...
- 每日英语:Foreign Tourists Skip Beijing
Overseas tourists continued to shun Beijing through 2013. shun:避开,避免,回避 Amid rising pollution and a ...
- L192 Virgin Galactic Completes Test of Spaceship to Carry Tourists
Virgin Galactic says its spacecraft designed to launch tourists into space completed an important te ...
- UOJ #30. [CF Round #278] Tourists
UOJ #30. [CF Round #278] Tourists 题目大意 : 有一张 \(n\) 个点, \(m\) 条边的无向图,每一个点有一个点权 \(a_i\) ,你需要支持两种操作,第一种 ...
- [UOJ30]/[CF487E]Tourists
[UOJ30]/[CF487E]Tourists 题目大意: 一个\(n(n\le10^5)\)个点\(m(m\le10^5)\)条边的无向图,每个点有点权.\(q(q\le10^5)\)次操作,操作 ...
- Tourists——圆方树
CF487E Tourists 一般图,带修求所有简单路径代价. 简单路径,不能经过同一个点两次,那么每个V-DCC出去就不能再回来了. 所以可以圆方树,然后方点维护一下V-DCC内的最小值. 那么, ...
随机推荐
- 微信小程序--代码构成---JSON 配置
在上一章中,我们通过开发者工具快速创建了一个 QuickStart 项目.你可以留意到这个项目里边生成了不同类型的文件: .json 后缀的 JSON 配置文件 .wxml 后缀的 WXML 模板文件 ...
- tempalte模板
tempalte模板层: 功能:为了更有逻辑的将数据库中的数据渲染到模板中: 模拟数据源: DB = [ {"hostname":"c1.com"," ...
- 宿主进程 [*.vshost.exe] & [*.vshost.exe.config]
宿主进程 [*.vshost.exe] & [*.vshost.exe.config] pdb文件: 英文全称:Program Database File 中文全称:程序数据库 文件 Debu ...
- exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
1.虽然,不是大错,还说要贴一下,由于我运行run-example streaming.NetworkWordCount localhost 9999的测试案例,出现的错误,第一感觉就是Spark没有 ...
- x86 版的 Arduino Intel Galileo 开发板的体验、分析和应用
1.前言 在今年(2013)罗马举办的首届欧洲 Make Faire 上,Intel 向对外发布了采用 x86 构架的 Arduino 开发板:Intel Galileo.这无疑是一个开源硬件领域的重 ...
- 通过awk获取netstat命令中的进程号
需要如下: 获取进程号
- 使用impala对kudu进行DML操作
将数据插入 Kudu 表 impala 允许使用标准 SQL 语句将数据插入 Kudu 插入单个值 创建表: CREATE TABLE my_first_table ( id BIGINT, name ...
- awk介绍
awk 是一个强大的文本处理工具,它将文本逐行读入,并进行切片,默认以空白格为分割符,对单个切片进行分析,处理. 用法: awk '{pattern + action}' {filenames} 尽管 ...
- windows配置tomcat https访问
主要参考两篇: http://blog.csdn.net/minute_man/article/details/53787682 http://blog.csdn.net/chow__zh/artic ...
- 071 SparkStreaming与SparkSQL集成
1.说明 虽然DStream可以转换成RDD,但是如果比较复杂,可以考虑使用SparkSQL. 2.集成方式 Streaming和Core整合: transform或者foreachRDD方法 Cor ...