319. Kalevich Strikes Back

Time limit per test: 0.5 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard

And yet again the Berland community can see that talent is always multi-sided. The talent is always seeking new ways of self-expression. This time genius Kalevich amazed everybody with his new painting "Rectangular Frames". The masterpiece is full of impenetrable meaning and hidden themes.

Narrow black rectangular frames are drawn on a white rectangular canvas. No two frames have a common point. Sides of each frame are parallel to the sides of the canvas.

The painting is very big and the reduced replica cannot pass the idea of the original drawing. That's why Kalevich requested that the simplified versions of the masterpiece should be used as replicas. The simplified version is the sequence of the areas of all facets of the original. A facet is a connected enclosed white area within the painting. The areas in the sequence should be written in the non-decreasing order.

Input

The first line of the input contains an integer N (1 ≤ N ≤ 60000) — the number of the frames on the drawing. The second line contains integer numbers W and H (1 ≤ WH ≤ 108).

Let's introduce the Cartesian coordinate system in such a way that the left bottom corner of the canvas has (0, 0) coordinate and the right top corner has the (WH) coordinate. The sides of the canvas are parallel to the axes.

The following N lines contain the description of the frames. Each description is composed of the coordinates of the two opposite corners of the corresponding frame x1y1x2y2(1 ≤ x1x2 < W; 1 ≤ y1y2 < Hx1 != x2y1 != y2). All coordinates are integers. No two frames have a common point.

Output

Write the desired sequence to the output.

Example(s)
sample input
sample output
1
3 3
2 1 1 2
1 8

矩形不相交,可能会内含。

使用线段树的扫描线,搞出保含关系,然后dfs一遍。

 /* ***********************************************
Author :kuangbin
Created Time :2014/5/1 16:10:22
File Name :E:\2014ACM\专题学习\数据结构\线段树\SGU319.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
struct Node
{
int l,r;
int ll,rr;//实际的左右区间
int c;//覆盖标记,懒惰标记
}segTree[MAXN*];
int x[MAXN];
struct Line
{
int x1,x2,y;
int id;
Line(){}
Line(int _x1,int _x2,int _y,int _id)
{
x1 = _x1;
x2 = _x2;
y = _y;
id = _id;
}
}line[MAXN];
bool cmp(Line a,Line b)
{
return a.y < b.y;
}
void push_down(int r)
{
if(segTree[r].l + == segTree[r].r)return;
if(segTree[r].c != -)
{
segTree[r<<].c = segTree[(r<<)|].c = segTree[r].c;
segTree[r].c = -;
}
}
void build(int i,int l,int r)
{
segTree[i].l = l;
segTree[i].r = r;
segTree[i].ll = x[l];
segTree[i].rr = x[r];
segTree[i].c = ;
if(l+ == r)return;
int mid = (l+r)/;
build(i<<,l,mid);
build((i<<)|,mid,r);
}
int pre[MAXN];
void Update(int i,Line e)
{
if(segTree[i].ll == e.x1 && segTree[i].rr == e.x2)
{
if(e.id > )
segTree[i].c = e.id;
else segTree[i].c = pre[-e.id];
return;
}
push_down(i);
if(e.x2 <= segTree[i<<].rr)Update(i<<,e);
else if(e.x1 >= segTree[(i<<)|].ll)Update((i<<)|,e);
else
{
Line tmp = e;
tmp.x2 = segTree[i<<].rr;
Update(i<<,tmp);
tmp = e;
tmp.x1 = segTree[(i<<)|].ll;
Update((i<<)|,tmp);
}
}
int query(int i,Line e)
{
if(segTree[i].c != -)
return segTree[i].c;
if(e.x2 <= segTree[i<<].rr)return query(i<<,e);
else if(e.x1 >= segTree[(i<<)|].ll)return query((i<<)|,e);
else
{
e.x2 = segTree[i<<].rr;
return query(i<<,e);
}
}
long long area[MAXN];
vector<int>vec[MAXN];
void dfs(int u)
{
int sz = vec[u].size();
for(int i = ;i < sz;i++)
{
int v = vec[u][i];
area[u] -= area[v];
dfs(v);
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
int w,h;
while(scanf("%d",&n) == )
{
scanf("%d%d",&w,&h);
area[] = (long long)w*h;
int x1,x2,y1,y2;
int tot = ;
for(int i = ;i <= n;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1 > x2)swap(x1,x2);
if(y1 > y2)swap(y1,y2);
area[i] = (long long)(x2-x1)*(y2-y1);
line[tot] = Line(x1,x2,y1,i);
x[tot++] = x1;
line[tot] = Line(x1,x2,y2,-i);
x[tot++] = x2;
}
sort(x,x+tot);
tot = unique(x,x+tot) - x;
build(,,tot-);
sort(line,line+*n,cmp);
for(int i = ;i <= n;i++)
vec[i].clear();
for(int i = ;i < *n;i++)
{
if(line[i].id > )
{
pre[line[i].id] = query(,line[i]);
vec[pre[line[i].id]].push_back(line[i].id);
}
Update(,line[i]);
}
dfs();
sort(area,area+n+);
for(int i = ;i <= n;i++)
{
printf("%I64d",area[i]);
if(i < n)printf(" ");
else printf("\n");
}
}
return ;
}

SGU 319. Kalevich Strikes Back (线段树)的更多相关文章

  1. SGU 319 Kalevich Strikes Back(线段树扫描线)

    题目大意: n个矩形,将一个大矩形分成 n+1 块.矩形之间不重合,可是包括.求这n+1个矩形的面积 思路分析: 用线段树记录他们之间的父子关系.然后dfs 计算面积. 当给出的矩形上边的时候,就要记 ...

  2. SGU 531. Bonnie and Clyde 线段树

    531. Bonnie and Clyde 题目连接: http://acm.sgu.ru/problem.php?contest=0&problem=531 Description Bonn ...

  3. SGU 311. Ice-cream Tycoon(线段树)

    311. Ice-cream Tycoon Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: standar ...

  4. SGU 180 Inversions(离散化 + 线段树求逆序对)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...

  5. SGU - 311 Ice-cream Tycoon(线段树)

    Description You've recently started an ice-cream business in a local school. During a day you have m ...

  6. BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)

    今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...

  7. bzoj3932--可持久化线段树

    题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...

  8. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  9. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

随机推荐

  1. VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。

    1.在项目自动生成的stdafx.h文件中添加下面头文件 #include <io.h> #include <fcntl.h> #include <stdio.h> ...

  2. 代理模式 (Proxy Pattern)

    代理模式的定义:为其他对象提供一种代理以控制对这个对象的访问.而对一个对象进行访问控制的一个原因是为了只有在我们确实需要这个对象时才对它进行创建和初始化.在某些情况下,一个对象不适合或者不能直接引用另 ...

  3. ECShop函数列表大全

    lib_time.php gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime(hour=NULL ...

  4. 完成一段简单的Python程序,使用函数实现用来判断输入数是偶数还是奇数

    #!/bin/usr/env python#coding=utf-8'''完成一段简单的Python程序,使用函数实现用来判断偶数和奇数'''def number_deal(a): if a%2==0 ...

  5. pt-find 使用实例

    pt-find - Find MySQL tables and execute actions, like GNU find. 用法:pt-find [OPTION...] [DATABASE...] ...

  6. pt-fifo-split使用

    percona-toolkit系列-pt-find http://blog.itpub.net/23249684/viewspace-1354308/ 在<mysql插入/更新数据>这篇文 ...

  7. Centos 7 通过挂载系统光盘搭建本地yum仓库的方法

    实验环境:CentOS 7 1:在media文件下创建一个目录  #创建一个www文件 cd /media/www 2: 挂载光盘,将光盘挂载在刚才创建的www文件下 mount /dev/cdrom ...

  8. div+css样式

    Div+Css 随着页面上的需求变大,许多的东西不再使用单纯的图片.按钮.文字,而是通过Div+Css来实现按钮,公司的需求就是这样,一直在弄这个模块,顺便的总结一下 列如下面的页面都是通过div+c ...

  9. Jquery 之 使用选择器

    jQuery选择器描述 jQuery选择器是jQuery框架的基础,jQuery对事件的处理.DOM操作.CSS动态控制.Ajax通信.动画设计都是在选择器基础上进行的.jQuery 选择器采用CSS ...

  10. ORACLE创建表之前判断表是否存在与SQL Server 对比使用

    在SQL Server 数据库中,我们在创建表之前删除表,有if exit()这样的语句,但是在oracle中却没有.如果直接使用drop table那么如果表不存在会报错,导致后续语句无法运行.因此 ...