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. learning at commad AT+CPSI

    [Purpose] Learning how to get mobile network info [Eevironment] Shell terminal, base on gcom command ...

  2. liunx 随笔集

    Linux 安装时 Customize Now(自定义选包)选包如下 base system  ->  base , compatibility libraries,debugging Tool ...

  3. window.open()打开页面

    一.window.open()支持环境:JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法:window.open(pageURL,name,pa ...

  4. HUSTOJ配置文件

    转载:http://blog.csdn.net/zhblue/article/details/7366194 经常有用户询问如何开发一些功能,实际上这些功能都已经有,或者部分实现了,只需要修改配置文件 ...

  5. :组合模式:Component

    #ifndef __COMPONENT_H__ #define __COMPONENT_H__ #include <iostream> #include <vector> us ...

  6. The issue about the GMT paper can't display all the seismograms

    I try to display seismograms using 'pssac' by the command: gmt pssac *.z -JX20c/40c -R0/// -Bx20+l'T ...

  7. 牛客第三场多校 H Diff-prime Pairs

    链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...

  8. Linux文件系统命令 rm

    命令名:rm 功能:删除某一个文件或者目录 eg: renjg@renjg-HP-Compaq-Pro--MT:~/WorkSpace$ ls BM3 gf k8s minicom_download ...

  9. <Codis><JedisPool><DeadLock>

    Overview Background: I start a thread [call thread A below]in Spark driver to handle opening files i ...

  10. <Web Crawler><Java><thread-safe queue>

    Basic Solution The simplest way is to build a web crawler that runs on a single machine with single ...