题目传传传送门:http://codeforces.com/contest/1028/problem/C

C. Rectangles

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given nn rectangles on a plane with coordinates of their bottom left and upper right points. Some (n−1)(n−1) of the given nn rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.

Find any point with integer coordinates that belongs to at least (n−1)(n−1) given rectangles.

Input

The first line contains a single integer nn (2≤n≤1326742≤n≤132674) — the number of given rectangles.

Each the next nn lines contains four integers x1x1, y1y1, x2x2 and y2y2 (−109≤x1<x2≤109−109≤x1<x2≤109, −109≤y1<y2≤109−109≤y1<y2≤109) — the coordinates of the bottom left and upper right corners of a rectangle.

Output

Print two integers xx and yy — the coordinates of any point that belongs to at least (n−1)(n−1) given rectangles.

Examples

input

Copy
  1. 3
    0 0 1 1
    1 1 2 2
    3 0 4 1
output

Copy
  1. 1 1
input

Copy
  1. 3
    0 0 1 1
    0 1 1 2
    1 0 2 1
output

Copy
  1. 1 1
input

Copy
  1. 4
    0 0 5 5
    0 0 4 4
    1 1 4 4
    1 1 4 4
output

Copy
  1. 1 1
input

Copy
  1. 5
    0 0 10 8
    1 2 6 7
    2 3 5 6
    3 4 4 5
    8 1 9 2
output

Copy
  1. 3 4
Note

The picture below shows the rectangles in the first and second samples. The possible answers are highlighted.

The picture below shows the rectangles in the third and fourth samples.

题意概括:

N个矩阵,每个矩阵的表示方法是给左下角和右上角的坐标,求一个点至少在(N-1)个矩阵内部,求这个点的坐标(如果有多个输出其中一个就可以了)。

解题思路:

比赛时TLE的思路是二维树状数组标记,然后查询找被标记了至少(N-1)次的点。

TLE code:

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <map>
  7. #define ll long long int;
  8. #define INF 0x3f3f3f3f
  9. using namespace std;
  10. const int MAXN = ;
  11. const int MAX = 1e9;
  12. int x[MAXN], y[MAXN];
  13. map<int,map<int, int> >mmp;
  14. int N, T;
  15.  
  16. int lowbit(int x)
  17. {
  18. return x&(-x);
  19. }
  20.  
  21. void add(int x, int y, int value)
  22. {
  23. for(int i = x; i <= MAX; i += lowbit(i))
  24. for(int j = y; j <= MAX; j += lowbit(j))
  25. mmp[i][j] += value;
  26. }
  27.  
  28. int sum(int x, int y)
  29. {
  30. int res = ;
  31. for(int i = x; i > ; i -= lowbit(i))
  32. for(int j = y; j > ; j -= lowbit(j))
  33. res+=mmp[i][j];
  34. return res;
  35. }
  36.  
  37. void init()
  38. {
  39. for(int i = ; i <= N; i++)
  40. for(int j = ; j <= N; j++)
  41. mmp[i][j] = ;
  42. }
  43.  
  44. int main()
  45. {
  46. int x1, y1, x2, y2;
  47. scanf("%d", &N);
  48. for(int i = ; i <= N; i++)
  49. {
  50. scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  51. x1++, x2++, y1++, y2++;
  52. x[i] = x1;
  53. y[i] = y1;
  54. add(x1, y1, );
  55. add(x2+, y1, -);
  56. add(x1, y2+, -);
  57. add(x2+, y2+, -);
  58. }
  59. for(int i = ; i <= N; i++)
  60. {
  61. if(sum(x[i], y[i]) >= N-)
  62. {
  63. printf("%d %d", x[i]-, y[i]-);
  64. break;
  65. }
  66. }
  67. return ;
  68. }

然而这道题其实是道YY题...求矩阵前缀交集和后缀交集,然后 O(n) 枚举每一个点不在交集中的情况(也就是该点前缀交后缀的情况),如果该点不在时存在合法交集,那么答案就出来了。

AC code:

  1. #include <bits/stdc++.h>
  2. #define INF 0x3f3f3f3f
  3. #define LL long long int
  4. using namespace std;
  5. const int MAXN = ;
  6. typedef struct Date{
  7. int x1, x2, y1, y2;
  8. };
  9. Date P[MAXN], st[MAXN], ed[MAXN];
  10. int N;
  11.  
  12. inline Date add(Date a, Date b)
  13. {
  14. Date res;
  15. res.x1 = max(a.x1, b.x1);
  16. res.y1 = max(a.y1, b.y1);
  17. res.x2 = min(a.x2, b.x2);
  18. res.y2 = min(a.y2, b.y2);
  19. return res;
  20. }
  21.  
  22. int main()
  23. {
  24. scanf("%d", &N);
  25. for(int i = ; i <= N; i++)
  26. {
  27. scanf("%d%d%d%d", &P[i].x1, &P[i].y1, &P[i].x2, &P[i].y2);
  28. }
  29. st[] = P[]; ed[N] = P[N];
  30. for(int i = ; i <= N; i++) st[i] = add(st[i-], P[i]);
  31. for(int i = N-; i >= ; i--) ed[i] = add(ed[i+], P[i]);
  32.  
  33. for(int i = ; i <= N; i++){
  34. Date cur;
  35. if(i == ) cur = ed[];
  36. else if(i == N) cur = st[N-];
  37. else cur = add(st[i-], ed[i+]);
  38. if(cur.x1 <= cur.x2 && cur.y1 <= cur.y2){
  39. printf("%d %d\n", cur.x1, cur.y1);
  40. break;
  41. }
  42. }
  43. return ;
  44. }

AIM Tech Round 5 (rated, Div. 1 + Div. 2) C. Rectangles 【矩阵交集】的更多相关文章

  1. AIM Tech Round 5 (rated, Div. 1 + Div. 2) (A, B, E)

    B.Unnatural Conditions 题目链接 : http://codeforces.com/contest/1028/problem/B #include<iostream> ...

  2. AIM Tech Round 5 (rated, Div. 1 + Div. 2)

    A. Find Square 找到对角线的两个点的坐标,这道题就迎刃而解了. inline void work(int n) { int m; cin >> m; memset(str, ...

  3. AIM Tech Round 5 (rated, Div. 1 + Div. 2) E(思维,构造)

    #include<bits/stdc++.h>using namespace std;long long a[150007];long long ans[150007];int main( ...

  4. AIM Tech Round 5 (rated, Div. 1 + Div. 2) D(SET,思维)

    #include<bits/stdc++.h>using namespace std;const long long mod = 1e9+7;char s[370007][27];long ...

  5. 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) 总结】【题解往前或往后翻,不在这】

    又是爆炸的一场 心态有点小崩.但问题不大.. 看A题,一直担心有多个正方形..小心翼翼地看完之后,毅然地交上去了. [00:08] A[Accpted] 然后开始看B题. 觉得和之前做的某题很像,但翻 ...

  6. 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) A】 Find Square

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找到左上角.往下一直走,往右一直走走到B边界就好. 中点的话.直接输出中位数 [代码] #include <bits/stdc ...

  7. 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) B】Unnatural Conditions

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让a+b的和为100000000...0这样的形式就好了 这样s(a+b)=1<=m就肯定成立了(m>=1) 然后至于s ...

  8. 【 AIM Tech Round 5 (rated, Div. 1 + Div. 2) C】Rectangles

    [链接] 我是链接,点我呀:) [题意] 给你n个矩形. 让你找出一个点(x,y) 使得这个点在其中至少(n-1)个矩形中. [题解] 若干个矩形交在一起的话. 它们所有的公共区域也会是一个矩形. 这 ...

  9. Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)

    A. Find Square time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...

随机推荐

  1. mysql 问题总结[转]

    一.Can't connect to MySQL server on 'localhost' (10061)   不能连接到 localhost 上的mysql分析:这说明“localhost”计算机 ...

  2. Oracle 数据库实例和数据库

    本文参考自oracle数据库实例,数据库的理解,纯属读书笔记,用于加深记忆. 先看Tom关于这二者的解释: 1.数据库 物理操作系统文件或磁盘的集合(我觉得可以理解为数据文件等).使用Oracle 1 ...

  3. 成功配置TOMCAT的LOG4J日志系统,格式:HTML+每天以YYYY-MM-DD.LOG命名的日志文件

    关于log4j.properties文件在web项目中放的位置,找过很多,最后实践结果是: 一.web项目 二.放在src的目录里面,然后项目生成后会自动在\WEB-INF\classes文件里有份l ...

  4. cloudemanager安装时出现8475 MainThread agent ERROR Heartbeating to 192.168.30.1:7182 failed问题解决方法(图文详解)

    不多说,直接上干货!   问题详情 解决这个问题简单的,是因为有进程占用了.比如 # ps aux | grep super root ? Ss : : /opt/cm-/lib64/cmf/agen ...

  5. 牛客网Java刷题知识点之拥塞发生的主要原因、TCP拥塞控制、TCP流量控制、TCP拥塞控制的四大过程(慢启动、拥塞避免、快速重传、快速恢复)

    不多说,直接上干货! 福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑          ...

  6. Spark-HBase集成错误之 java.lang.NoClassDefFoundError: org/htrace/Trace

    在进行Spark与HBase 集成的过程中遇到以下问题: java.lang.IllegalArgumentException: Error while instantiating 'org.apac ...

  7. poi 多行合并

    poi做多行合并,一定需要先绘制单元格,然后写入数据,最后合并,不然各种坑啊. 合并单元格所使用的方法: sheet.addMergedRegion( CellRangeAddress  cellRa ...

  8. 深入理解JavaScript系列(32):设计模式之观察者模式

    介绍 观察者模式又叫发布订阅模式(Publish/Subscribe),它定义了一种一对多的关系,让多个观察者对象同时监听某一个主题对象,这个主题对象的状态发生变化时就会通知所有的观察者对象,使得它们 ...

  9. js根据子目录数目显示父级目录

    需求:<ul>中<li>数量为0,则不显示<ul>以及<b>:<div>中<ul>数量为0,则不显示<div> 1. ...

  10. 安卓API版本