sgu Kalevich Strikes Back
这道题就是求一个大矩形被n个矩形划分成n+1个部分的面积,这些矩形之间不会相交,可能包含。。
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define maxn 120100
using namespace std; long long s[maxn];
vector<int>g[maxn];
int pre[maxn];
int X[maxn];
int n,m,w,h,x1,y1,x2,y2;
struct node
{
int l,r;
int ll,rr;
int cover;
}tree[maxn*]; struct line
{
int y,x1,x2,lr;
bool operator <(const line &a)const
{
return y<a.y;
}
}p[maxn]; void build(int i,int l,int r)
{
tree[i].l=l;
tree[i].r=r;
tree[i].ll=X[l];
tree[i].rr=X[r];
tree[i].cover=;
if(r-l==) return ;
int mid=(l+r)>>;
build(i<<,l,mid);
build(i<<|,mid,r);
}
void down(int i)
{
if(tree[i].l+==tree[i].r) return;
if(tree[i].cover!=-)
{
tree[i<<].cover=tree[i<<|].cover=tree[i].cover;
tree[i].cover=-;
}
}
void update(int i, line a)
{
if(tree[i].ll==a.x1&&tree[i].rr==a.x2)
{
if(a.lr>)
tree[i].cover=a.lr;
else
tree[i].cover=pre[-a.lr];
return ;
}
down(i);
if(a.x2<=tree[i<<].rr) update(i<<,a);
else if(a.x1>=tree[i<<|].ll) update(i<<|,a);
else
{
line tmp=a;
tmp.x2=tree[i<<].rr;
update(i<<,tmp);
tmp=a;
tmp.x1=tree[i<<|].ll;
update(i<<|,tmp);
}
} int search1(int i,line m)
{
if(tree[i].cover!=-)
{
return tree[i].cover;
}
if(m.x2<=tree[i<<].rr) return search1(i<<,m);
else if(m.x1>=tree[i<<|].ll) return search1(i<<|,m);
else
{
line tmp;
tmp=m;
tmp.x2=tree[i<<].rr;
return search1(i<<,tmp);
}
}
void dfs(int u)
{
for(int i=; i<(int)g[u].size(); i++)
{
int v=g[u][i];
s[u]-=s[v];
dfs(v);
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
g[i].clear();
}
scanf("%d%d",&w,&h);
s[]=(long long)w*h;
int t1=;
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);
s[i]=(long long)(x2-x1)*(y2-y1);
p[t1].y=y1;
p[t1].x1=x1;
p[t1].x2=x2;
p[t1].lr=i;
X[t1++]=x1;
p[t1].y=y2;
p[t1].x1=x1;
p[t1].x2=x2;
p[t1].lr=-i;
X[t1++]=x2;
}
sort(X,X+t1);
t1=unique(X,X+t1)-X;
build(,,t1-);
sort(p,p+*n);
for(int i=; i<*n; i++)
{
if(p[i].lr>)
{
pre[p[i].lr]=search1(,p[i]);
g[pre[p[i].lr]].push_back(p[i].lr);
}
update(,p[i]);
}
dfs();
sort(s,s+n+);
for(int i=; i<=n; i++)
{
if(i==n) printf("%I64d\n",s[i]);
else printf("%I64d ",s[i]);
}
}
return ;
}
sgu Kalevich Strikes Back的更多相关文章
- SGU 319. Kalevich Strikes Back (线段树)
319. Kalevich Strikes Back Time limit per test: 0.5 second(s)Memory limit: 65536 kilobytes input: st ...
- SGU 319 Kalevich Strikes Back(线段树扫描线)
题目大意: n个矩形,将一个大矩形分成 n+1 块.矩形之间不重合,可是包括.求这n+1个矩形的面积 思路分析: 用线段树记录他们之间的父子关系.然后dfs 计算面积. 当给出的矩形上边的时候,就要记 ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 树形DP求树的重心 --SGU 134
令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...
随机推荐
- PYTHON线程知识再研习E---条件变量同步Condition
Python提供的Condition对象提供了对复杂线程同步问题的支持.Condition被称为条件变量,除了提供与Lock类似的 acquire和release方法外,还提供了wait和notify ...
- ops
consists several key projects separately stand-alone connected entities massive scalability massive ...
- QA笑话----杂思
QA工程师走进酒吧,要了一杯啤酒,要了0杯啤酒,要了999999999杯啤酒,要了一只蜥蜴,要了-1杯啤酒,要了一个sfdeljknesv,酒保从容应对,QA工程师 很满意.接下来,一名顾客来到了同一 ...
- Erlang ODBC 处理中文
erlang处理utf8字符集相对比较简单,因为它是用integer的list来保存所有的string的,所以处理什么字符集都没关系. 话虽这么说,但我在使用erlang的ODBC处理中文时,着实费了 ...
- db2的select语句在db2 client上执行正确,JDBC连接数据库时报错
db2的select语句在db2 client上执行正确,JDBC连接数据库时报错. sql语句是:select ...from QUALIFIER.tableName fetch first 21 ...
- poj 2100 Graveyard Design(尺取法)
Description King George has recently decided that he would like to have a new design for the royal g ...
- poj 1011 Sticks (DFS+剪枝)
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127771 Accepted: 29926 Descrip ...
- [Javascript] Task queue & Event loop.
Javascript with Chorme v8 engine works like this : For Chorme engine, v8, it has call stack. And all ...
- JSP实现分页功能
分页须知知识点: (1)JDBC2.0的可滚动结果集. (2)HTTP GET请求. 一.可滚动结果集 Connection con = DriverManager.getConnection( ...
- Dynamics CRM 常用 C# 方法集合
Plugin(C#) 分派 AssignRequest assign = new AssignRequest(); assign.Assignee = prEntity["ownerid&q ...