BZOJ4049 [Cerc2014] Mountainous landscape
首先对于一个给定的图形,要找到是否存在答案非常简单。。。
只要维护当然图形的凸包,看一下是否有线段在这条直线上方,直接二分即可,单次询问的时间复杂度$O(logn)$
现在用线段树维护凸包,即对于一个区间$[l, r]$,我们维护点$[P_l, P_{r +1}]$形成的凸包
于是每次查询只要在线段树上二分,总复杂度$O(nlogn + nlog^2n)$(建树 + 查询)
/**************************************************************
Problem: 4049
User: rausen
Language: C++
Result: Accepted
Time:5052 ms
Memory:73960 kb
****************************************************************/ #include <cstdio>
#include <vector> using namespace std;
typedef long long ll;
const int N = 1e5 + ; int read(); int n; struct point {
int x, y;
point(int _x, int _y) : x(_x), y(_y) {}
point() {} inline point operator + (const point &p) const {
return point(x + p.x, y + p.y);
}
inline point operator - (const point &p) const {
return point(x - p.x, y - p.y);
}
inline ll operator * (const point &p) const {
return 1ll * x * p.y - 1ll * y * p.x;
} inline void get() {
x = read(), y = read();
} friend inline ll calc(const point &a, const point &b, const point &c) {
return (a - b) * (c - b);
}
} p[N]; struct convex {
vector <point> s; inline void clear() {
s.clear();
}
#define top ((int) s.size() - 1)
inline void insert(const point &p) {
while (top > && calc(p, s[top - ], s[top]) <= ) s.pop_back();
s.push_back(p);
} #define mid (l + r >> 1)
inline bool query(const point &p, const point &q) {
int l = , r = top - ;
while (l < r) {
if (calc(s[mid], p, q) < calc(s[mid + ], p, q)) r = mid;
else l = mid + ;
}
return calc(s[l], p, q) < || calc(s[l + ], p, q) < ;
}
#undef mid
#undef top
}; struct seg {
seg *ls, *rs;
convex c; #define Len (1 << 16)
inline void* operator new(size_t, int f = ) {
static seg mempool[N << ], *c;
if (f) c = mempool;
c -> ls = c -> rs = NULL, c -> c.clear();
return c++;
}
#undef Len #define mid (l + r >> 1)
void build(int l, int r) {
int i;
for (i = l; i <= r + ; ++i) c.insert(p[i]);
if (l == r) return;
(ls = new()seg) -> build(l, mid);
(rs = new()seg) -> build(mid + , r);
} int query(int l, int r, int L, int R, const point &p, const point &q) {
if (R < l || r < L) return ;
if (L <= l && r <= R) {
if (!c.query(p, q)) return ;
if (l == r) return l;
}
int res = ls -> query(l, mid, L, R, p, q);
return res ? res : rs -> query(mid + , r, L, R, p, q);
}
#undef mid
} *T; int main() {
int Tmp, i;
for (Tmp = read(); Tmp; --Tmp) {
n = read();
for (i = ; i <= n; ++i) p[i].get();
(T = new()seg) -> build(, n - );
for (i = ; i < n - ; ++i)
printf("%d ", T -> query(, n - , i + , n - , p[i], p[i + ]));
puts("");
}
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}
BZOJ4049 [Cerc2014] Mountainous landscape的更多相关文章
- BZOJ4049][CERC2014]Mountainous landscape-[线段树+凸包+二分]
Description 现在在平面上给你一条折线P1P2P3...Pn. x坐标是严格单调递增的.对于每一段折线PiPi+1,请你找一个最小的j,使得j>i且走在PiPi+1的人能看到折线PjP ...
- Mountainous landscape
Description 现在在平面上给你一条折线 \(P_1P_2 \cdots P_n\) . \(x\) 坐标是严格单调递增的.对于每一段折线 \(P_iP_{i+1}\) ,请你找一个最小的 \ ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- NOIp2018模拟赛三十五
两道大数据结构把我砸懵 成绩:未提交 Orz xfz两道正解 A:[BZOJ4049][CREC2014B]mountainous landscape B:CJB的大作(CF改编题)
- SAP SLT (Landscape Transformation) 企业定制培训
No. Item Remark 1 SAP SLT概述 SAP Landscape Transformation Overview 2 SAP SLT 安装与配置<1> for abap ...
- iPad apple-touch-startup-image实现portrait和landscape
iPad apple-touch-startup-image实现portrait和landscape 为ipad制作web应用程序的启动画面时发现个问题,只能显示竖屏图,横屏图出不来,网上的朋友都说无 ...
- JS 获取和监听屏幕方向变化(portrait / landscape)
移动设备的屏幕有两个方向: landscape(横屏)和portrait(竖屏),在某些情况下需要获取设备的屏幕方向和监听屏幕方向的变化,因此可以使用Javascript提供的 MediaQueryL ...
- [JS代码]如何判断ipad或者iphone是否为横屏或者竖屏 - portrait或者landscape
//判断横屏或者竖屏 function orient() { //alert('gete'); if (window.orientation == 0 || window.orientation == ...
- iOS的横屏(Landscape)与竖屏(Portrait)InterfaceOrientation
http://www.molotang.com/articles/1530.html 接着上篇写的触摸事件,这次借机会整理下iOS横屏和竖屏的翻转方向支持,即InterfaceOrientation相 ...
随机推荐
- Ubuntu 安装BCM 43142无线网卡驱动
ubuntu14.04 安装 bcm43142无线网卡 用命令lspci 查看无线网卡类型 然后下载对应的无线网卡驱动. 之后,使用下列命令安装,即可搜索无线热点了: sudo apt-get ins ...
- Eclipse下Tomcat插件的安装
在Eclipse下安装Tomcat插件使开发,编译,发布变的相当的简单,下面就说一下安装的过程,很简单的: 1.先下载一个tomcat插件 地址:http://www.eclipsetotale.co ...
- IE7 float:left失效的解决方法
<div id="a" style="width:500px"> <div id="b" style="widt ...
- C#:绘图问题
1.设置DPI Bitmap bitmap2 = new Bitmap((int)w, (int)h); bitmap2.SetResolution(, ); 2.设置Graphic(如:去锯齿等) ...
- 基于webrtc的视频通话时webrtc的接口调用流程
场景: 1.A call B 2.B answer 3.A connected with B 共同的步骤: A 和 B 都需要初始化webrtc模块,创建peerconnectionfactory 步 ...
- css3 calc()方法详解
calc()对大家来说,或许很陌生,不太会相信calc()是css中的部分.因为看其外表像个函数,既然是函数为何又出现在CSS中呢?这一点也让我百思不得其解,今天有一同事告诉我,说CSS3中有一个属性 ...
- jquery 新闻滚动效果
$(function () { var scrollTimer = null; var delay = 2000; //1.鼠标对新闻触发mouseout事件后每2s调用scr ...
- [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序实现继承
这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第十一篇:为ASP.NET MVC应用程 ...
- 第四章· ucos系统及其任务
来自为知笔记(Wiz)
- ios下移除原生样式
之前遇到过这个问题,今天无意中在网上看见博文 记录一下. 设置这个就好: -webkit-appearance : none ;