IOI1998 hdu1828 poj1177 Picture
写了一发扫描线竟然狂WA不止,hdu死活过不了,poj和当时IOI的数据(还花了我1dsdn积分。。)都过了。
然后看到谋篇blog里有评论,把数据拿下来发现WA了。
数据是
2
0 0 1 1
1 0 2 1
就是有一条边贴着了,这个时候应该先加入新的边再删除,否则会算重。
另外,线段树不用清零哦。
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm> using namespace std; typedef int data_type;
const int N = + ; data_type disc[N];
int disc_tot; int get_hash(data_type a[], int n, data_type x) {
return lower_bound(a, a + n, x) - a;
} struct Rect {
data_type x1, y1, x2, y2;
void input() {
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
disc[disc_tot++] = y1, disc[disc_tot++] = y2;
}
} rect[N]; struct Event {
int id, tp;
data_type key() const {
if(tp == ) return rect[id].x1;
else return rect[id].x2;
}
bool operator < (const Event &rhs) const {
if(key() != rhs.key()) return key() < rhs.key();
return tp > rhs.tp; // 键值相同先加入再删除
}
Event() {}
Event(int id, int tp) : id(id), tp(tp) {}
} eve[N]; struct SegmentTree {
data_type sum[N * ];
int cnt[N * ], lp[N * ], rp[N * ], num[N * ];
#define lc s << 1
#define rc s << 1 | 1
void update(int s, int l, int r) {
if(cnt[s]) sum[s] = disc[r+] - disc[l], lp[s] = rp[s] = num[s] = ;
else if(l == r) sum[s] = , lp[s] = rp[s] = num[s] = ;
else {
sum[s] = sum[lc] + sum[rc];
lp[s] = lp[lc], rp[s] = rp[rc];
num[s] = num[lc] + num[rc] - (rp[lc] && lp[rc]);
}
}
void modify(int s, int l, int r, int L, int R, int d) {
if(L <= l && r <= R) cnt[s] += d;
else {
int mid = (l + r) >> ;
if(L <= mid) modify(lc, l, mid, L, R, d);
if(mid < R) modify(rc, mid + , r, L, R, d);
}
update(s, l, r);
}
#undef lc
#undef rc
} seg; bool solve() {
int n; if(scanf("%d", &n) == EOF) return ;
disc_tot = ;
for(int i = ; i < n; i++) {
rect[i].input();
eve[i << ] = Event(i, );
eve[i << | ] = Event(i, -);
}
sort(disc, disc + disc_tot);
disc_tot = unique(disc, disc + disc_tot) - disc;
sort(eve, eve + (n << ));
data_type res = , last = ;
for(int i = ; i < (n << ); i++) {
const Event &e = eve[i];
if(i) res += (seg.num[] << ) * (e.key() - eve[i-].key());
int l = get_hash(disc, disc_tot, rect[e.id].y1);
int r = get_hash(disc, disc_tot, rect[e.id].y2) - ;
if(l <= r) seg.modify(, , disc_tot - , l, r, e.tp);
res += abs(seg.sum[] - last), last = seg.sum[];
}
return printf("%d\n", res), ;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
#endif
while(solve()); return ;
}
IOI1998 hdu1828 poj1177 Picture的更多相关文章
- [POJ1177]Picture
[POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...
- poj1177 Picture 矩形周长并
地址:http://poj.org/problem?id=1177 题目: Picture Time Limit: 2000MS Memory Limit: 10000K Total Submis ...
- POJ1177 Picture —— 求矩形并的周长 线段树 + 扫描线 + 离散化
题目链接:https://vjudge.net/problem/POJ-1177 A number of rectangular posters, photographs and other pict ...
- CQOI2005 三角形面积并 和 POJ1177 Picture
1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 1664 Solved: 443[Submit][Stat ...
- POJ1177 Picture 线段树+离散化+扫描线
求最终的覆盖图形周长,写这种代码应该短而精确,差的比较远 /* Problem: 1177 User: 96655 Memory: 348K Time: 32MS Language: C++ Resu ...
- POJ-1177 Picture 矩形覆盖周长并
题目链接:http://poj.org/problem?id=1177 比矩形面积并麻烦点,需要更新竖边的条数(平行于x轴扫描)..求横边的时候,保存上一个结果,加上当前长度与上一个结果差的绝对值就行 ...
- 【hdu1828/poj1177】线段树求矩形周长并
题意如图 题解:这题非常类似与矩形面积并,也是维护一个被覆盖了一次以上的线段总长. 但是周长要算新出现的,所以每次都要和上一次做差求绝对值. x轴做一遍,y轴做一遍. 但是有个问题:矩形边界重合的时候 ...
- HDU1828:Picture
浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:http://acm.hdu.edu.cn/showproblem.php? ...
- 【poj1177】 Picture
http://poj.org/problem?id=1177 (题目链接) 题意 求矩形周长并. Solution 转自:http://www.cnblogs.com/Booble/archive/2 ...
随机推荐
- @Transient注解
以下两个包都包含@Transient注解 java.beans.Transient; javax.persistence.Transient; 使用@Transient时注意区别二者
- 《JavaScript启示录》摘抄
1.JavaScript预包装的9个原生的对象构造函数: Number(),String(),Boolean(),Object(),Array(),Function(),Data(),RegExp() ...
- 上下切换js
<div class="wview"> <span class="prevs" id="prevs-j"></ ...
- RPM包制作最简单样例
相关开发RPM的包要安装 Summary: the Firt RPM of Sky Name: hellow Version: 0.1 Release: Vendor: PA soft(aguncn@ ...
- Java从入门到精通(一)
Java编程可以分为三个方向 ① Java se (j2se) 桌面开发 ② Java ee (j2ee) WEB开发 ③ Java me (j2me) 手机开发 java se 是基础中的基础 Ja ...
- SQLite入门与分析(九)---VACUUM命令分析
VACUUM命令是SQLite的一个扩展功能,模仿PostgreSQL中的相同命令而来.若调用VACUUM带一个表名或索引名, 则将整理该表或索引.在SQLite 1.0中,VACUUM命令调用 gd ...
- Python标准库之urllib,urllib2
urllib模块提供了一些高级接口,用于编写需要与HTTP服务器交互的客户端.典型的应用程序包括从网页抓取数据.自动化.代理.网页爬虫等. 在Python 2中,urllib功能分散在几个不同的库模块 ...
- crtmpserver系列之一:流媒体概述
阅读目录 概述 流媒体系统的组成 媒体文件封装 传输协议 回到顶部 概述 所谓流媒体按照字面意思理解就是像流一样的媒体,看起来像是废话.流媒体现在司空见惯,所以一般人大概不会有疑问.事实上在流媒体还没 ...
- Android 常用UI控件之TabHost(3)在4.0不显示图标的解决方案
1,自定义 TabWidget 上每个tab的view 2,用多个图片
- VS2010里属性窗口中的生成操作
,无,编译 ,内容 ,嵌入的资源...分别是什么意思? 如果是类.cs文件,就得编译之后你才能使用的.如果是txt,excle这种文件,就属性内容或者资源文件了. @普通用户: 内容(Content) ...