UVA11983 - Weird Advertisement(扫描线)

题目链接

题目大意:给你n个覆盖矩形,问哪些整数点是被覆盖了k次。

题目大意:这题和hdu1542是一个题型。可是这题求的是覆盖k次的点。所以pushup里面就要改一下。详细的看代码把。大概的意思就是每次都是通过以下的两个孩子节点的覆盖信息更新父节点的覆盖信息。然后这题也是须要离散化建树。比較须要注意的是这题和hdu1542不一样的地方是边界,由于那题是求面积。边界并不须要考虑。而这题是求点的个数,边界上的点也是要算的。建树的时候考虑叶子节点范围的时候就要包含边界上的点。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std; #define lson(x) (x<<1)
#define rson(x) ((x<<1) | 1) const int maxn = 60005;
typedef long long ll; struct Line { int x, y1, y2, flag;
Line (int x, int y1, int y2, int flag) { this->x = x;
this->y1 = y1;
this->y2 = y2;
this->flag = flag;
} bool operator < (const Line & a) const {
return x < a.x;
}
}; struct Node { int l, r, add;
ll s[12];
void set (int l, int r, int add) { this->l = l;
this->r = r;
this->add = add;
}
}node[maxn * 4]; vector<int> pos;
vector<Line> L;
int n, k; void pushup(int u) { for (int i = 0; i <= k; i++)
node[u].s[i] = 0L; int t;
if (node[u].l == node[u].r) {
t = min(k, node[u].add);
node[u].s[t] = pos[node[u].l + 1] - pos[node[u].l];
} else {
for (int i = 0; i <= k; i++) {
t = min (i + node[u].add, k);
node[u].s[t] += node[lson(u)].s[i] + node[rson(u)].s[i];
}
}
} void build (int u, int l, int r) { node[u].set(l, r, 0); if (l == r) {
pushup(u);
return;
} int m = (l + r)>>1;
build(lson(u), l, m);
build(rson(u), m + 1, r);
pushup(u);
} void update (int u, int l, int r , int v) { if (l <= node[u].l && r >= node[u].r) {
node[u].add += v;
pushup(u);
return;
} int m = (node[u].l + node[u].r)>>1;
if (l <= m)
update (lson(u), l, r, v);
if (r > m)
update (rson(u), l, r, v);
pushup(u);
} void init () { int x1, y1, x2, y2;
scanf ("%d%d", &n, &k);
L.clear();
pos.clear(); for (int i = 0; i < n; i++) { scanf ("%d%d%d%d", &x1, &y1, &x2, &y2); L.push_back(Line(x1, y1, y2 + 1, 1));
L.push_back(Line(x2 + 1, y1, y2 + 1, -1));
pos.push_back(y1);
pos.push_back(y2 + 1);
} sort(L.begin(), L.end());
sort(pos.begin(), pos.end());
pos.erase (unique(pos.begin(), pos.end()), pos.end()); build(1, 0, (int)pos.size() - 1);
} ll solve () { init();
ll ans = 0; int l, r;
for (int i = 0; i < L.size() - 1; i++) { l = lower_bound(pos.begin(), pos.end(), L[i].y1) - pos.begin();
r = lower_bound(pos.begin(), pos.end(), L[i].y2) - pos.begin(); update (1, l, r - 1, L[i].flag);
ans += node[1].s[k] * (L[i + 1].x - L[i].x);
}
return ans;
} int main () { int T;
scanf ("%d", &T); for (int cas = 1; cas <= T; cas++)
printf ("Case %d: %lld\n", cas, solve());
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVA11983 - Weird Advertisement(扫描线)的更多相关文章

  1. uva 11983 Weird Advertisement 扫描线

    Weird Advertisement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/probl ...

  2. UVA 11983 Weird Advertisement

    题意:求矩形覆盖k次以上的区域总面积. 因为k≤10,可以在线段树上维护覆盖次数为0,...,k, ≥k的长度数量. 然后就是一个离散化以后扫描线的问题了. 离散化用的是半开半闭区间,以方便表示没有被 ...

  3. UVA 11983 Weird Advertisement --线段树求矩形问题

    题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...

  4. UVA 11983 Weird Advertisement(线段树求矩形并的面积)

    UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...

  5. [转载]完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...

  6. 【转】线段树完全版~by NotOnlySuccess

    线段树完全版  ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...

  7. 《完全版线段树》——notonlysuccess

    转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...

  8. 【转】 线段树完全版 ~by NotOnlySuccess

    载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...

  9. 【转载】完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...

随机推荐

  1. [LeetCode283]Move Zeros将一个数组中为0的元素移至数组末尾

    题目: Given an array nums, write a function to move all 0's to the end of it while maintaining the rel ...

  2. 使用GDB在远程开发机上调试

    由于一些环境限制,很多学生很可能需要在开发机器上调试.但是,由于对计算机资源的开发限制.在本地的直接机的发展GDB环境配置问题已经成为,其实,我们可以利用这段时间GDB自带gdbserver工具将能够 ...

  3. H. 硬币的水问题II

    H. 硬币水题II Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: ...

  4. VisualStudioOnline协同工作流程

    VisualStudioOnline协同工作流程 项目负责人登陆自己的vsonline新建项目就不多说了. 直接从邀请队友开始 项目负责人操作 被邀请的邮箱必须是微软的邮箱(也就是可以登录visual ...

  5. SQL SERVER SQLOS的任务调度

    原文:SQL SERVER SQLOS的任务调度 原文地址:http://blogs.msdn.com/b/apgcdsd/archive/2011/11/24/sql-server-sqlos.as ...

  6. 【转】Robot Framework 快速入门

    目录 介绍 概述 安装 运行demo 介绍样例应用程序 测试用例 第一个测试用例 高级别测试用例 数据驱动测试用例 关键词keywords 内置关键词 库关键词 用户定义关键词 变量 定义变量 使用变 ...

  7. DNA和纳米(Nano)Fusion技术的发展趋势

    细观国内外有关DNA与Nano技术的报道.不得不承认存在不小的差距,并且差距有继续拉大的趋势. 在我们国内,DNA技术是作为遗产基因来对待的.引用的有关中文參考资料一般比較陈旧.缺少參考价值.在发达国 ...

  8. ehCache浅谈(转)

    ehcache FAQ中提到 Remember that a value in a cache element is globally accessible from multiple threads ...

  9. OCP-1Z0-051-标题决心-文章2称号

    2. View the Exhibit to examine the description for the SALES table. Which views can have all DML ope ...

  10. 高通公司 MSM8K GPT异常原因分析无法开机的问题

    问题分析过程如下面: 一. MSM8916台gpt概率问题:采用QPST emmc software download下载软件工具后,无法开机.例如下面的附图: log分析是userdata分区未成功 ...