这题觉得似乎不难的样子……

但硬是没有做出来,真是不知说什么好喵~

注意到没有两条共线的线段具有公共点,没有重合的线段

说明每个十字形最多涉及一个水平线段和一个竖直线段

这说明我们可以二分了:每条线段两端砍掉delta长度后,有没有线段有公共点?

很水的扫描线吧~  按 X 轴扫描,先把横的线段扫进去,再用竖的线段去查询

但是写法是很重要的,我说我不用线段树你信喵?我说我连离散化都不用你信喵?

约大爷教你做人!@Ruchiose
 
 #include <cstdio>
#include <algorithm>
#include <set>
const int size=; namespace IOspace
{
inline int getint()
{
register int num=;
register char ch=, last;
do last=ch, ch=getchar(); while (ch<'' || ch>'');
do num=num*+ch-'', ch=getchar(); while (ch>='' && ch<='');
if (last=='-') num=-num;
return num;
}
inline void putint(int num, char ch='\n')
{
char stack[];
register int top=;
if (num==) stack[top=]='';
for ( ;num;num/=) stack[++top]=num%+'';
for ( ;top;top--) putchar(stack[top]);
if (ch) putchar(ch);
}
} struct line
{
int x, y, l;
inline line() {}
inline line(int _x, int _y, int _l):x(_x), y(_y), l(_l) {}
};
struct node
{
int type;
int x, y1, y2;
inline node() {}
inline node(int _type, int _x, int _y1, int _y2):type(_type), x(_x), y1(_y1), y2(_y2) {}
inline bool operator < (node a) const {return x!=a.x?x<a.x:type*y2>a.type*a.y2;}
}; int n, m, k;
line h[size], s[size];
node q[size];
std::multiset<int> t;
inline int max(int x, int y) {return x>y?x:y;}
inline void swap(int & a, int & b) {int t=a; a=b; b=t;}
inline bool query(int, int);
inline bool check(int); int main()
{
n=IOspace::getint(); m=IOspace::getint();
for (int i=;i<n;i++) s[i].x=IOspace::getint(), s[i].y=IOspace::getint(), s[i].l=IOspace::getint();
for (int i=;i<m;i++) h[i].x=IOspace::getint(), h[i].y=IOspace::getint(), h[i].l=IOspace::getint(); int left=, right=, mid;
for (int i=;i<n;i++) right=max(right, s[i].l);
while (left+<right)
{
mid=(left+right)>>;
if (check(mid)) left=mid;
else right=mid;
} IOspace::putint(left); return ;
} inline bool query(int l, int r)
{
return t.lower_bound(l)!=t.upper_bound(r);
}
inline bool check(int d)
{
k=;
for (int i=;i<m;i++) if (h[i].l>=(d<<))
{
q[k++]=node(, h[i].x+d, h[i].y, );
q[k++]=node(, h[i].x+h[i].l-d, h[i].y, -);
}
for (int i=;i<n;i++) if (s[i].l>=(d<<))
q[k++]=node(, s[i].x, s[i].y+d, s[i].y+s[i].l-d);
std::sort(q, q+k);
t.clear();
for (int i=;i<k;i++)
{
if (q[i].type)
{
if (q[i].y2==) t.insert(q[i].y1);
else t.erase(t.find(q[i].y1));
}
else
if (query(q[i].y1, q[i].y2))
return true;
}
return false;
}

本傻受益匪浅系列

只存操作(包括插入、删除、询问)真是无比的高大上,跪跪跪

还有那鬼畜的查询写法

(set).lower_bound(l)!=(set).upper_bound(r)

可以查询 [l..r] 中是否有数存在,至于为什么这样是对的而不是别的样子了,大家在纸上画画就知道了吧

其实更好理解的是

当 (set).lower_bound(l)==(set).upper_bound(r) 时, [l..r] 中一定没有数

lower_bound是为了将 l 算入 [l..r] 中,upper_bound(r) 也是为了将 r 算入 [l..r] 中

真是跪跪跪跪跪跪跪跪

[codeforces 391D2]Supercollider的更多相关文章

  1. 【Codeforces Rockethon 2014】Solutions

    转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engi ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. 修改Azure Website 移动服务 默认时区

    Azure Website 默认时区为国际标准时间,对中国用户来说不太方便友好,如何设置成北京时间呢? 打开Azure Website的“配置”页,找到“应用设置”节点. 在应用设置中添加设置项,密钥 ...

  2. win10系统输入法用户体验

    因为现在的输入法好多的广告弹窗所以我一直用系统原生的输入法,自从去年升级win10以后一直在用自带的输入法, 1.用户界面设计 win10系统自带的输入法用户界面设计非常扁平化,没有哪些所谓的皮肤啥的 ...

  3. (转)HTML文档头部信息

    原文:http://www.cnblogs.com/sunyunh/archive/2012/07/25/2609199.html HTML(3)HTML文档头部信息   <!DOCTYPE h ...

  4. java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

    java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

  5. leetcode 238 Product of Array Except Self

    这题看似简单,不过两个要求很有意思: 1.不准用除法:最开始我想到的做法是全部乘起来,一项项除,可是中间要是有个0,这做法死得很惨. 2.空间复杂度O(1):题目说明了返回的那个数组不算进复杂度分析里 ...

  6. What is hmux in resin?

    When I start the Resin server it says hmux listening to localhost:6802 What is this hmux? Is this a ...

  7. php大力力 [024节]PHP中的字符串连接操作(2015-08-27)

    2015-08-27 php大力力024.PHP中的字符串连接操作 PHP中的字符串连接操作  阅读:次   时间:2012-03-25 PHP字符串的连接的简单实例 时间:2013-12-30 很多 ...

  8. 13、C#基础整理(枚举)

    枚举 1.概念和作用 (1)用于存放常量,只能在定义时赋值(防止编程过程中恶意篡改,并且防止对同一事物的不同赋值--统一化) (2)定义的枚举类型需要包含该类型的所有可能的值 (3)方法.类.内部都可 ...

  9. 在windows下安装GIT

    Git是一个免费的.开源的版本控制软件.在Windows上安装git,一般为msysgit,官方下载地址为:http://code.google.com/p/msysgit/downloads/lis ...

  10. dll强签名的由来和作用

    C# dll强签名介绍 之前基本没有这个概念,直到有一天我们的dll被反编译了,导致我们的代码基本上被看到了,才想起来要保护dll的安全性,因为C#语言的在编译过程中会产生中间语言导致dll很容易被反 ...