首先对于一个给定的图形,要找到是否存在答案非常简单。。。

只要维护当然图形的凸包,看一下是否有线段在这条直线上方,直接二分即可,单次询问的时间复杂度$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的更多相关文章

  1. BZOJ4049][CERC2014]Mountainous landscape-[线段树+凸包+二分]

    Description 现在在平面上给你一条折线P1P2P3...Pn. x坐标是严格单调递增的.对于每一段折线PiPi+1,请你找一个最小的j,使得j>i且走在PiPi+1的人能看到折线PjP ...

  2. Mountainous landscape

    Description 现在在平面上给你一条折线 \(P_1P_2 \cdots P_n\) . \(x\) 坐标是严格单调递增的.对于每一段折线 \(P_iP_{i+1}\) ,请你找一个最小的 \ ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. NOIp2018模拟赛三十五

    两道大数据结构把我砸懵 成绩:未提交 Orz xfz两道正解 A:[BZOJ4049][CREC2014B]mountainous landscape B:CJB的大作(CF改编题)

  5. SAP SLT (Landscape Transformation) 企业定制培训

    No. Item Remark 1 SAP SLT概述 SAP Landscape Transformation Overview 2 SAP SLT 安装与配置<1> for abap ...

  6. iPad apple-touch-startup-image实现portrait和landscape

    iPad apple-touch-startup-image实现portrait和landscape 为ipad制作web应用程序的启动画面时发现个问题,只能显示竖屏图,横屏图出不来,网上的朋友都说无 ...

  7. JS 获取和监听屏幕方向变化(portrait / landscape)

    移动设备的屏幕有两个方向: landscape(横屏)和portrait(竖屏),在某些情况下需要获取设备的屏幕方向和监听屏幕方向的变化,因此可以使用Javascript提供的 MediaQueryL ...

  8. [JS代码]如何判断ipad或者iphone是否为横屏或者竖屏 - portrait或者landscape

    //判断横屏或者竖屏 function orient() { //alert('gete'); if (window.orientation == 0 || window.orientation == ...

  9. iOS的横屏(Landscape)与竖屏(Portrait)InterfaceOrientation

    http://www.molotang.com/articles/1530.html 接着上篇写的触摸事件,这次借机会整理下iOS横屏和竖屏的翻转方向支持,即InterfaceOrientation相 ...

随机推荐

  1. Linux的硬链接为何不能链接目录

    Linux中的目录文件是特殊的文件,其中的数据是一个关联列表的,像c++中的map,或者Python中的dict,保存每个文件名(包括子目录,Linux中一切皆文件!)到iNode的映射.iNode本 ...

  2. 友善p35屏

    友善p35 屏,x轴方向从左往右移(0——>320),Y轴方向从上往下开始(0——>240)

  3. java 笔试题 字符串旋转

    package com.shb.java; /** * 取出第一个重复的字符 * @author shaobn * @date 2016-9-28 * @package_name com.shb.ja ...

  4. IPC

    IPC,全名Inter Process Communication即进程间通讯,在同一台机器上的两个进程就用IPC,不能跨物理机器。IPC包括共享内存、队列、信号量等几种方式,由于IPC通讯效率之高, ...

  5. 如何清除PL/SQL中的缓存

    每次查询前清空缓存10g以上:alter system flush buffer_cache;9i:ALTER SESSION SET EVENTS 'immediate trace name flu ...

  6. IUS tcl cmd

    Incisive simulator中的command-line language基于TCL. Ncsim> command [-modifier] [-options] [arguments] ...

  7. 网站禁止右键点击js

    <script>        function stop() {            return false;        }        document.oncontextm ...

  8. ql Server 高频,高并发访问中的键查找死锁解析

    死锁对于DBA或是数据库开发人员而言并不陌生,它的引发多种多样,一般而言,数据库应用的开发者在设计时都会有一定的考量进而尽量避免死锁的产生.但有时因为一些特殊应用场景如高频查询,高并发查询下由于数据库 ...

  9. :selected

    描述: 查找所有选中的选项元素 HTML 代码: <select> <option value="1">Flowers</option> < ...

  10. 给NIOS II CPU增加看门狗定时器并使用

    给NIOS II CPU增加看门狗定时器并使用   配置看门狗定时器: 设置计时溢出时间为1秒 计数器位宽为32位 勾选No Start/Stop control bits 勾选Fixed perio ...