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相 ...
随机推荐
- 起因:dell超级密码算号器 1F66
班里有几个比较调皮的同学~(显然不包括我[开玩笑的]) 当初班长设置了密码,结果那几个玩拳皇的想玩,就找我删除了密码~ 最后有个大神就过来设置了BIOS.有种终于出动了的样子.有种我看你怎么办的样子. ...
- AJAX-----07XMLHttpRequest对象的处理返回的JSON类型数据
要玩json首先就需要知道一般都数据是怎么处理的: <!DOCTYPE html> <html lang="en"> <head> <me ...
- mysql中and和or
and的优先级高于or,所以一个sql语句中如果and和or同时出现,则or要加括号
- vs2005水晶报表无法运行在X64机器上
要下载补丁:CRRedist2005_X64.msi http://download.csdn.net/download/gcy007/7106933
- Dynamics AX 2012 R2 安装 AIF IIS上的Web服务
1.为什么使用IIS上的WEB服务 组件? 如果你要在Dynamics AX Service中使用HTTP Adapter,那么你就要安装IIS上的WEB服务 组件.HTTP Adapter会在IIS ...
- 错误,这个如何解决呢?内存溢出的问提。把JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m 还是不行
java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at ja ...
- 覆盖的面积(HDU 1255 线段树)
覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem D ...
- easyui 动态列
$.post('${createLink(action:"build Columns url ")}', params, function(data){ var columns = ...
- html、css 【珍藏】
行内元素:会在水平方向排列,不能包含块级元素,设置width无效,height无效(可以设置line-height),margin上下无效,padding上下无效. 块级元素: 各占据一 ...
- 关于 Oracle 的数据导入导出及 Sql Loader (sqlldr) 的用法
在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中2. 建立数据库间的 ...