写了一发扫描线竟然狂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的更多相关文章

  1. [POJ1177]Picture

    [POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...

  2. poj1177 Picture 矩形周长并

    地址:http://poj.org/problem?id=1177 题目: Picture Time Limit: 2000MS   Memory Limit: 10000K Total Submis ...

  3. POJ1177 Picture —— 求矩形并的周长 线段树 + 扫描线 + 离散化

    题目链接:https://vjudge.net/problem/POJ-1177 A number of rectangular posters, photographs and other pict ...

  4. CQOI2005 三角形面积并 和 POJ1177 Picture

    1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 1664  Solved: 443[Submit][Stat ...

  5. POJ1177 Picture 线段树+离散化+扫描线

    求最终的覆盖图形周长,写这种代码应该短而精确,差的比较远 /* Problem: 1177 User: 96655 Memory: 348K Time: 32MS Language: C++ Resu ...

  6. POJ-1177 Picture 矩形覆盖周长并

    题目链接:http://poj.org/problem?id=1177 比矩形面积并麻烦点,需要更新竖边的条数(平行于x轴扫描)..求横边的时候,保存上一个结果,加上当前长度与上一个结果差的绝对值就行 ...

  7. 【hdu1828/poj1177】线段树求矩形周长并

    题意如图 题解:这题非常类似与矩形面积并,也是维护一个被覆盖了一次以上的线段总长. 但是周长要算新出现的,所以每次都要和上一次做差求绝对值. x轴做一遍,y轴做一遍. 但是有个问题:矩形边界重合的时候 ...

  8. HDU1828:Picture

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:http://acm.hdu.edu.cn/showproblem.php? ...

  9. 【poj1177】 Picture

    http://poj.org/problem?id=1177 (题目链接) 题意 求矩形周长并. Solution 转自:http://www.cnblogs.com/Booble/archive/2 ...

随机推荐

  1. Tesseract 3.02中文字库训练

    Tesseract 3.02中文字库训练 下载chi_sim.traindata字库下载tesseract-ocr-setup-3.02.02.exe 下载jTessBoxEditor用于修改box文 ...

  2. Decision Boundaries for Deep Learning and other Machine Learning classifiers

    Decision Boundaries for Deep Learning and other Machine Learning classifiers H2O, one of the leading ...

  3. SQl为表添加和删除列

    1.删除列: Alter Table TransBetRecord     drop column ToProjectCode 2.添加列: Alter Table TransBetRecord    ...

  4. [dp]POJ2559 && HDOJ1506 Largest Rectangle in a Histogram

    题意 给n个条形的高度, 问能放的最大矩形面积 分析: 从左到右 从右到左 各搞一遍 分别记录      L[i]记录列(从前往后)标 第几列开始 可以往后放高度为a[i]的矩形  R[i]记录列(从 ...

  5. [codility]Equi-leader

    http://codility.com/demo/take-sample-test/equileader 一开始想到从左和右两边开始扫取众数,但求众数又要重新扫一遍,这样复杂度就是O(n^2)了.此题 ...

  6. javaweb学习总结(二十八)——JSTL标签库之核心标签

    一.JSTL标签库介绍 JSTL标签库的使用是为弥补html标签的不足,规范自定义标签的使用而诞生的.使用JSLT标签的目的就是不希望在jsp页面中出现java逻辑代码 二.JSTL标签库的分类 核心 ...

  7. linux进程间通信方式

    (1)管道(Pipe):管道可用于具有亲缘关系进程间的通信,允许一个进程和另一个与它有共同祖先的进程之间进行通信. (2)命名管道(named pipe):命名管道克服了管道没有名字的限制,因此,除具 ...

  8. 【原创】MIPS中断系统的板级验证及实例测试

    “五一”假期前后这约五天时间,终于将MIPS中断系统进行了板级验证及实例测试.因为老师给的交叉编译工具不会用,所以测试代码完全用MIPS汇编编写.使用MARS而没有用QtSpim,其实我觉得SPIM这 ...

  9. ☀【Node】处理文件上传

    Node入门 √http://www.nodebeginner.org/index-zh-cn.html Node.js中所用的fs.renameSync出错:Error: EXDEV, cross- ...

  10. Azure 媒体服务支持 DASH 实时传送流

    Kilroy Hughes Azure媒体服务数字媒体架构师 本文重点介绍 Azure 媒体服务支持的 DASH 实时传送流功能,同时阐述如何利用这些功能将实时和点播自适应流传送至 Web 浏览器 ...