写了一发扫描线竟然狂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. Jquer学习

    1:什么是Jquery 2:jquery的例子 3:后记

  2. 使用struts2标签<s:action无法显示引用页面问题

    使用过程中参考:http://www.cnblogs.com/lihuiyy/archive/2012/03/23/2411601.html 个人使用: 1.引用页面 <s:action nam ...

  3. .bat批处理脚本让cmd命令行提示符cd到工作目录 (转)

    打开cmd,检查命令行提示符所在的默认位置(目录),进入该目录用notepad++创建一个文件,输入 @echo offrem 这个符号表示该行是注释.rem 进入f盘,需要先切换盘符,成功后才能进入 ...

  4. 带节假日JS万年历控件代码

    <form name="CLD" class="content"> <table width="100%" border= ...

  5. Html中如何让超链接a、图片img居中

    一.问题来源 修改博客页面时,突然想到 二.解决办法 2.1原来办法 在img和a中加入align="center",发现不行 2.2百度答案 <div align=&quo ...

  6. 未来 USB Type-C 将可靠软体判断线材是否符合规定

    USB Type-C 插头允许通过的电流和功率比过去常见的 USB 规范要大得多,因此从市面上「随便买一条」USB Type-C 的充电线的危险也同样大得多,毕竟不是所有的线材能承受的电流都一样,万一 ...

  7. tbody添加垂直滚动条

    法一: 用2个table: <table width="300" border="0" cellpadding="0" cellspa ...

  8. CreateObject("Wscript.Shell")用法

    WScript.Shell是WshShell对象的ProgID,创建WshShell对象可以运行程序.操作注册表.创建快捷方式.访问系统文件夹.管理环境变量. 该对象有一个run方法. Run 方法创 ...

  9. [HDU 4433]locker[DP]

    题意: 给出密码做的现状和密码, 每次可以移动连续的最多3列, 向上或向下, 求将密码调出来所需要的最少步数. 思路: 首先应看出,恢复的过程中, 调每一位的时间顺序是不影响的, 不妨就从左到右一位位 ...

  10. hdu4655Cut Pieces

    http://acm.hdu.edu.cn/showproblem.php?pid=4655 先以最大的来算为 N*所有的排列数  再减掉重复的 重复的计算方法:取相邻的两个数的最小值再与它前面的组合 ...