题意:

n<=1e5,abs(x[i]),abs(y[i]<=1e9

思路:这是正解

离散后线段树强打,数据结构越学越傻

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 1100000
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1)
struct arr1
{
int x1,y1,x2,y2;
}a[N]; struct arr2
{
int x,y1,y2,z;
}c[N]; struct tree
{
int a,s,x;
}t[N<<]; int b[N],d[N],q[N],m; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void swap(int &x,int &y)
{
int t=x;x=y;y=t;
} int hash1(int x)
{
int l=;
int r=m;
while(l<=r)
{
int mid=(l+r)>>;
if(b[mid]==x) return d[mid];
if(b[mid]<x) l=mid+;
else r=mid-;
}
} bool cmp(arr2 a,arr2 b)
{
return a.x<b.x;
} void pushdown(int p)
{
int l=p<<;
int r=l+;
if(!t[p].a) return;
t[l].s=t[l].s+t[p].a;
t[l].a=t[l].a+t[p].a;
t[r].s=t[r].s+t[p].a;
t[r].a=t[r].a+t[p].a;
t[p].a=;
} void pushup(int p)
{
if(t[p<<].s<t[p+p+].s)
{
t[p].s=t[p+p+].s;
t[p].x=t[p+p+].x;
}
else
{
t[p].s=t[p<<].s;
t[p].x=t[p<<].x;
}
} void build(int l,int r,int p)
{
if(l>r) return;
t[p].a=;
t[p].x=l;
if(l==r) return;
int mid=(l+r)>>;
build(l,mid,p<<);
build(mid+,r,p<<|);
} int query(int l,int r,int x,int y,int p)
{
if(x<=l&&r<=y) return t[p].s;
pushdown(p);
int mid=(l+r)>>;
int ret=-;
if(x<=mid) ret=query(l,mid,x,y,p<<);
if(y>mid)
{
int t=query(mid+,r,x,y,p<<|);
if(t>ret) ret=t;
}
return ret;
} void update(int l,int r,int x,int y,int v,int p)
{
if(x<=l&&r<=y)
{
t[p].s+=v;
t[p].a+=v;
return;
}
pushdown(p);
int mid=(l+r)>>;
if(x<=mid) update(l,mid,x,y,v,p<<);
if(y>mid) update(mid+,r,x,y,v,p<<|);
pushup(p);
} int main()
{
// freopen("cf1028C.in","r",stdin);
// freopen("cf1028C.out","w",stdout);
int x;
scanf("%d",&x);
int k1=x;
m=;
int n=;
for(int i=;i<=x;i++)
{
scanf("%d%d%d%d",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2);
b[++m]=a[i].x1;
b[++m]=a[i].y1;
b[++m]=a[i].x2;
b[++m]=a[i].y2;
}
sort(b+,b+m+);
d[]=;
for(int i=;i<=m;i++)
if(b[i]==b[i-]) d[i]=d[i-];
else d[i]=d[i-]+;
q[]=b[];
int len=;
for(int i=;i<=m;i++)
if(b[i]!=b[i-]) q[++len]=b[i]; for(int i=;i<=x;i++)
{
c[++n].x=hash1(a[i].x1);
c[n].y1=hash1(a[i].y1);
c[n].y2=hash1(a[i].y2);
c[n].z=;
c[++n].x=hash1(a[i].x2)+;
c[n].y1=hash1(a[i].y1);
c[n].y2=hash1(a[i].y2);
c[n].z=-;
}
sort(c+,c+n+,cmp);
int line=;
int row=;
for(int i=;i<=n;i++)
{
line=max(line,c[i].x);
row=max(row,c[i].y2);
}
build(,row,); int j=;
for(int i=;i<=line;i++)
{
while(j<=n&&c[j].x==i)
{
update(,row,c[j].y1,c[j].y2,c[j].z,);
// printf("%d %d %d\n",c[j].y1,c[j].y2,c[j].z);
j++;
}
int k=query(,row,,row,);
//printf("%d %d\n",i,k);
if(k>=k1-)
{
// int p=find(1,row,1,row,1);
int p=t[].x;
// printf("%d %d\n",i,p);
int x=q[i];
int y=q[p];
printf("%d %d\n",x,y);
return ;
}
}
return ;
}

【CF1028C】Rectangles(线段树)的更多相关文章

  1. Codeforces 524E Rooks and Rectangles 线段树

    区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define ...

  2. [CF983D]Arkady and Rectangles[线段树+可删堆/set]

    题意 你有一个无限大的绘图板,开始颜色是\(0\) , 你将进行\(n\) 次绘图,第\(i\) 次绘图会将左下角为 \((x_1, y_1)\),右上角为\((x_2, y_2)\) 的矩形涂成颜色 ...

  3. VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值

    E. Rooks and Rectangles Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemse ...

  4. hdu2461 Rectangles 线段树--扫描线

    You are developing a software for painting rectangles on the screen. The software supports drawing s ...

  5. VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线

    题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...

  6. 【做题】CSA72G - MST and Rectangles——Borůvka&线段树

    原文链接 https://www.cnblogs.com/cly-none/p/CSA72G.html 题意:有一个\(n \times n\)的矩阵\(A\),\(m\)次操作,每次在\(A\)上三 ...

  7. 线段树+扫描线 NAIPC 2019 Intersecting Rectangles

    你看看你有多菜,一点线段树的小小的运用,就不会写了: 题意:如果矩阵有交集,输出1,否则输出0(不包含内嵌): 思路:本题求交集,还得不包括内嵌的情况: 做过一道是求面积的题.跟这道类似,但在这里定义 ...

  8. POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21734   Accepted: 8179 Descrip ...

  9. 线段树---Atlantis

    题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...

随机推荐

  1. c#和Java中的接口

    使用场景: 在c#和Java中: 1.接口可以实现“多继承”(多实现),一个类只能继承自一个父类,但是可以实现多个接口. 2.接口解决了不同类型之间的多态问题,比如鱼与船不是同一类型,但是都能在水里“ ...

  2. c#List结合IEqualityComparer求交集

    List元素类: public class MultiPointSearchingRet { public int ID { get; set; } public string PlateNumber ...

  3. Windows上PostgreSQL安装配置教程

    Windows上PostgreSQL安装配置教程 这篇文章主要为大家详细介绍了Windows上PostgreSQL安装配置教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 PostgreSQL的 ...

  4. pandas关联mysql并读写数据库

    1.代码读写mysql,必须安装关联mysql的工具 操作如下命令: sudo apt-get install mysql-server mysql-clientsudo apt-get instal ...

  5. vmware虚拟机安装Windows 7后虚拟机自动挂起

    vmware虚拟机安装windows7后在一段时间中没有操作,虚拟机会自动挂起,是因为windows7中的设置的自动睡眠,打开[控制面板]=>[电源选项]=>[选择关闭显示器时间]将下面两 ...

  6. 标准C++(2)

    一.类 C++是一种面向对象的语言,它在C语言的基础上添加了一种新的数据结构,类 ——class class是一种复合型的数据结构 它能够由不同类型的变量及函数组成 C++中的class与struct ...

  7. 03IO端口寻址和访问控制方式

    1. I/O端口和寻址 CPU 为了访问 I/O 接口控制器或者控制卡上的数据和状态信息,需要首先指定他们的地址.这种地址就称为I/O端口地址或简称端口.通常一个 I/O 控制器包含访问数据的数据端口 ...

  8. python入门:输出1-10以内除去7的所有数(经典)

    #!/usr/bin/env python # -*-coding:utf-8 -*- #输出1-10以内除去7的所有数(经典) """ 给kaishi赋值为1,whil ...

  9. python3通过Beautif和XPath分别爬取“小猪短租-北京”租房信息,并对比时间效率(附源代码)

    爬虫思路分析: 1. 观察小猪短租(北京)的网页 首页:http://www.xiaozhu.com/?utm_source=baidu&utm_medium=cpc&utm_term ...

  10. Python中的魔法函数__repr__和__str__的实质性区别

    str 和 repr 方法:是自定义类的字符串描述,这两种都是比较 Pythonic 的方式去控制对象转化为字符串的方式. 调用这两个方法,返回的都是字符串.但是这两个方法又有一些区别 ** 1 两种 ...