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内的最小值. 那么, ...
随机推荐
- echarts 模拟迁徙
echarts 3 的功能貌似加了不少额 官方demo:http://echarts.baidu.com/demo.html#geo-lines 地图是基于地理地图的 百度提供了一些地图:http:/ ...
- 一个良好划分Activity创建步骤的BaseActivity
一个Activity的创建过程其实包含几个不同的步骤,基本上都是在onCreate函数中完成的,这些步骤主要有: 设置页面的布局文件 初始化页面包含的控件 设置页面控件的点击响应事件 处理页面的业务逻 ...
- 使用Github Pages和Hexo构建个人博客
Github Pages可以创建免费的静态站点,支持自带主题.支持自制页面等,并且可以使用Jekyll或者Hexo等静态博客框架进行管理. 独立博客是博客园等博客平台之外的一个良好补充,相比使用虚拟主 ...
- 解决 Ionic 浏览器跨域问题
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...
- python 保存小数位,控制保存几位
不知道怎么展示浮点数长度?? 看看例子就清楚了 a=0.2343545434564 print('%.3f'%a) #加点保留X个print('%3f'%a) #默认保留小数6个print('%03f ...
- Python 多进程multiprocessing
一.python多线程其实在底层来说只是单线程,因此python多线程也称为假线程,之所以用多线程的意义是因为线程不停的切换这样比串行还是要快很多.python多线程中只要涉及到io或者sleep就会 ...
- Codeforces 177G2 Fibonacci Strings KMP 矩阵
原文链接https://www.cnblogs.com/zhouzhendong/p/CF117G2.html 题目传送门 - CF177G2 题意 定义斐波那契字符串如下: $s_1="a ...
- byte数据常量池问题
[代码] public class BufferPoolDemo { public static void main(String[] args) { Integer i1=127; Integer ...
- Linux下java开发环境配置总结
1 安装JDK,卸载以前的jdk,安装jdk1.8 : 参考:http://www.jb51.net/os/RedHat/73016.html 需要注意配置环境变量中的路径要和当前安装的jdk路径一致 ...
- P4781 【模板】拉格朗日插值
P4781 [模板]拉格朗日插值 证明 :https://wenku.baidu.com/view/0f88088a172ded630b1cb6b4.html http://www.ebola.pro ...