【CF1028C】Rectangles(线段树)
题意:
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(线段树)的更多相关文章
- Codeforces 524E Rooks and Rectangles 线段树
区域安全的check方法就是, 每行都有哨兵或者每列都有哨兵,然后我们用y建线段树, 维护在每个y上的哨兵的x的最值就好啦. #include<bits/stdc++.h> #define ...
- [CF983D]Arkady and Rectangles[线段树+可删堆/set]
题意 你有一个无限大的绘图板,开始颜色是\(0\) , 你将进行\(n\) 次绘图,第\(i\) 次绘图会将左下角为 \((x_1, y_1)\),右上角为\((x_2, y_2)\) 的矩形涂成颜色 ...
- 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 ...
- hdu2461 Rectangles 线段树--扫描线
You are developing a software for painting rectangles on the screen. The software supports drawing s ...
- VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...
- 【做题】CSA72G - MST and Rectangles——Borůvka&线段树
原文链接 https://www.cnblogs.com/cly-none/p/CSA72G.html 题意:有一个\(n \times n\)的矩阵\(A\),\(m\)次操作,每次在\(A\)上三 ...
- 线段树+扫描线 NAIPC 2019 Intersecting Rectangles
你看看你有多菜,一点线段树的小小的运用,就不会写了: 题意:如果矩阵有交集,输出1,否则输出0(不包含内嵌): 思路:本题求交集,还得不包括内嵌的情况: 做过一道是求面积的题.跟这道类似,但在这里定义 ...
- POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]
Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21734 Accepted: 8179 Descrip ...
- 线段树---Atlantis
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...
随机推荐
- oracle中print_table存储过程实例介绍
oracle中pro_print_table存储过程实例介绍 存储过程(Stored Procedure),就是一组用于完成特定数据库功能的SQL语句集,该SQL语句集经过编译后存储在数据库系统中.这 ...
- Oracle数据库常用的Sql语句整理
Oracle数据库常用的Sql语句整理 查看当前用户的缺省表空间 : select username,default_tablespace from user_users; 2.查看用户下所有的表 : ...
- VC下的C语言程序随机数的产生
本文章适用于VC编译器,VC编译器里有个rand()函数,我们用它来实现取随机数. #include <stdio.h> #include<stdlib.h> //随机数的头文 ...
- C++图书馆管理系统项目中部分功能代码实现(书籍推荐)
bool UserServiceImpl::Compare1(Book b1,Book b2)//按照借阅次数比较{ if(b1.GetCnt() > b2.GetCnt()) { return ...
- python入门:用户登录,三次错误机会
#!/usr/bin/env python # -*- coding:utf-8 -*- #用户登录,三次机会重试 #主要分为两个部分,一部分是写三次循环,一部分写用户输入 #用户登录的实现,循环3次 ...
- spartan6不能直接把时钟连到IO上
1.问题的提出:spartan6中不允许时钟信号直接连到IO口上面? 2.解决办法: ODDR2的使用 ODDR2Primitive: Double Data Rate Output D Flip-F ...
- Python基础:字符串(string)
字符串的常用操作 字符串与数组一样,支持索引操作.切片与遍历 索引.切片操作: name = 'jason' name[0] 'j' name[1:3] 'as' 遍历: for char in na ...
- GoF23种设计模式之行为型模式之迭代器模式
一.概述 给定一种语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子.二.适用性1.当访问一个聚合对象的内容而无需暴露它的内部表示的时候.2.当对聚合对象的多 ...
- cpu位图
SMP处理器中要用到cpu位图,用来维护系统内CPU的状态信息,具有代表性的有: cpu_possible_map.cpu_online_map.cpu_present_map. static DEC ...
- install mongodb on macos
Update Homebrew’s package database. In a system shell, issue the following command: brew update 2 In ...