You are developing a software for painting rectangles on the screen. The software supports drawing several rectangles and filling some of them with a color different from the color of the background. You are to implement an important function. The function answer such queries as what is the colored area if a subset of rectangles on the screen are filled.

扫描线裸题

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn=; int st[maxn<<],cov[maxn<<],y[maxn];
int Q[maxn]; struct rect{
int x1,y1,x2,y2;
}R[maxn]; struct seg{
int x,y1,y2,c;
bool operator < (const seg a)const{
return x<a.x;
}
}s[maxn]; inline void build(){
memset(st,,sizeof(st));
memset(cov,,sizeof(cov));
} void pushup(int o,int l,int r){
if(cov[o])st[o]=y[r]-y[l];
else if(l+==r)st[o]=;
else st[o]=st[o<<]+st[o<<|];
} void update(int o,int l,int r,seg a){
if(a.y1<=y[l]&&a.y2>=y[r]){
cov[o]+=a.c;
pushup(o,l,r);
return;
}
if(l+==r)return;
int m=l+((r-l)>>);
if(a.y1<y[m])update(o<<,l,m,a);
if(a.y2>y[m])update(o<<|,m,r,a);
pushup(o,l,r);
} int main(){
int n,m,c=;
while(scanf("%d%d",&n,&m)!=EOF&&n+m){
printf("Case %d:\n",++c);
for(int i=;i<=n;++i)scanf("%d%d%d%d",&R[i].x1,&R[i].y1,&R[i].x2,&R[i].y2);
build();
for(int q=;q<=m;++q){
int k;
scanf("%d",&k);
int cnt=;
for(int i=;i<=k;++i){
int num;
scanf("%d",&num);
++cnt;
s[cnt].x=R[num].x1;s[cnt].y1=R[num].y1;s[cnt].y2=R[num].y2;
s[cnt].c=;
y[cnt]=R[num].y1;
++cnt;
s[cnt].x=R[num].x2;s[cnt].y1=R[num].y1;s[cnt].y2=R[num].y2;
s[cnt].c=-;
y[cnt]=R[num].y2;
}
sort(y+,y+cnt+);
int t=unique(y+,y+cnt+)-(y+);
sort(s+,s+cnt+);
int sum=;
for(int j=;j<cnt;++j){
update(,,t,s[j]);
sum+=st[]*(s[j+].x-s[j].x);
}
update(,,t,s[cnt]);
printf("Query %d: %d\n",q,sum);
}
printf("\n");
}
return ;
}

hdu2461 Rectangles 线段树--扫描线的更多相关文章

  1. hdu 1828 线段树扫描线(周长)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  2. hdu1542 Atlantis (线段树+扫描线+离散化)

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  3. HDU 1542 - Atlantis - [线段树+扫描线]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)

    版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...

  5. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  6. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  7. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  8. HDU 4419 Colourful Rectangle --离散化+线段树扫描线

    题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...

  9. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

随机推荐

  1. java 数据溢出和编译错误的差别

    int a=100000000000;编译错误,超出int范围 int a=2100000000; int b=a*12020200;数据溢出,a并未溢出,但b在通过a计算后的数据溢出 long e= ...

  2. java 一些容易忽视的小点-数据类型和运算符篇

    注释 文档注释:   以"/**"开头以"*/"结尾,注释中包含一些说明性的文字及一些JavaDoc标签(后期写项目时,可以生成项目的API) 行注释:   以 ...

  3. Vue + Element UI 实现权限管理系统(搭建开发环境)

    技术基础 开发之前,请先熟悉下面的4个文档 vue.js2.0中文, 优秀的JS框架 vue-router, vue.js 配套路由 vuex,vue.js 应用状态管理库 Element,饿了么提供 ...

  4. Ubuntu 16.04 中安装谷歌 Chrome 浏览器

    http://jingyan.baidu.com/article/335530da98061b19cb41c31d.html 根据教程安装成功!! http://askubuntu.com/quest ...

  5. python之路-网络基础

    1.什么是网络: 通过网络设备将各个设备连接在一起,使用协议让设备之间可以通信,共享资源,这些组成了一个网络. 2.osi七层模式: 国际标准化组织(ISO)创建OSI(开放系统互联)参考模型,希望不 ...

  6. AttributeError: 'cx_Oracle.Cursor' object has no attribute 'numbersAsStrings'

    转载自:https://www.wengbi.com/thread_77579_1.html 最近在本地搭建Django开发环境,Django 1.11,python 2.7.11,数据库Oracle ...

  7. windows添加PDF虚拟打印机

    添加PDF虚拟打印机(果真姜还是老的辣,我摸索了两天没结果的事情,大佬轻轻松松两分钟搞定...) 这种PDF虚拟打印机的功能是将需要被打印的内容写到当前系统的指定目录下的指定文件中.整个过程都不需要连 ...

  8. RabbitMQ 队列、消息持久化

    RabbitMQ的消息队列的持久化是一个很不错的功能,设置也非常简单.如下代码: 1.设置队列持久化(在声明队列的时候设置) channel.QueueDeclare(queue: "q.l ...

  9. 完全卸载vs2013 2015

    /uninstall /force 解压你的vs2013的安装包(iso格式). cd到解压后的文件夹 vs_ultimate.exe /uninstall /force 或者创建一个快捷方式到桌面 ...

  10. bootstrap动态生成层级ul-li 新闻预览 常用方法

    <div class="row" id="add-withinfosortId-row" style="display: none"& ...