题意:

求矩形覆盖K次以上的面积

分析:

k很小,可以开K颗线段树,用sum[rt][i]来保存覆盖i次的区间和,K次以上全算K次

// File Name: 11983.cpp
// Author: Zlbing
// Created Time: 2013/7/21 16:06:54 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--) #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 const int MAXN=6e4+;
struct seg{
int x1,x2,y;
int flag;
bool operator <(const seg& rsh)const{
return y<rsh.y;
}
}G[MAXN];
int hash[MAXN]; int col[MAXN<<];
int sum[MAXN<<][]; int n,m;
void build(int l,int r,int rt)
{
col[rt]=;
sum[rt][]=hash[r+]-hash[l];
for(int i=;i<=m;i++)sum[rt][i]=;
if(l==r)return;
int m=(l+r)>>;
build(lson);
build(rson);
}
void pushup(int rt,int l,int r)
{
if(col[rt]>=m)
{
memset(sum[rt],,sizeof(sum[rt]));
sum[rt][m]=hash[r+]-hash[l];
}
else if(l==r)
{
memset(sum[rt],,sizeof(sum[rt]));
sum[rt][col[rt]]=hash[r+]-hash[l];
}
else{
for(int i=;i<col[rt];i++)sum[rt][i]=;
for(int i=col[rt];i<m;i++)
{
sum[rt][i]=sum[rt<<][i-col[rt]]+sum[rt<<|][i-col[rt]];
}
sum[rt][m]=;
for(int i=m-col[rt];i<=m;i++)
{
sum[rt][m]+=sum[rt<<][i]+sum[rt<<|][i];
}
}
}
void update(int L,int R,int flag,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
col[rt]+=flag;
pushup(rt,l,r);
return;
}
int m=(l+r)>>;
if(L<=m)update(L,R,flag,lson);
if(R>m)update(L,R,flag,rson);
pushup(rt,l,r);
}
int main()
{
int T;
scanf("%d",&T);
int cas=;
while(T--)
{
scanf("%d%d",&n,&m);
int a,b,c,d;
int xlen=;
for(int i=;i<n;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
c++,d++;
G[xlen]=(seg){a,c,b,};
//G[xlen].x1=a,G[xlen].x2=c,G[xlen].y=b,G[xlen].flag=1;
hash[xlen]=a;
xlen++;
G[xlen]=(seg){a,c,d,-};
//G[xlen].x1=a,G[xlen].x2=c,G[xlen].y=d,G[xlen].flag=-1;
hash[xlen]=c;
xlen++;
}
sort(G,G+xlen);
sort(hash,hash+xlen);
int len=unique(hash,hash+xlen)-hash;
LL ans=;
build(,xlen-,);
for(int i=;i<xlen-;i++)
{
int x1=lower_bound(hash,hash+len,G[i].x1)-hash;
int x2=lower_bound(hash,hash+len,G[i].x2)-hash-;
update(x1,x2,G[i].flag,,xlen-,);
//printf("sum[1][m]=%I64d h=%d\n",sum[1][m],G[i+1].y-G[i].y);
ans+=(LL)sum[][m]*(LL)(G[i+].y-G[i].y);
}
printf("Case %d: %lld\n",cas++,ans);
}
return ;
}

UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]的更多相关文章

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

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

  2. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  3. hdu1542 线段树扫描线求矩形面积的并

    题意:       给你n个正方形,求出他们的所占面积有多大,重叠的部分只能算一次. 思路:       自己的第一道线段树扫描线题目,至于扫描线,最近会写一个总结,现在就不直接在这里写了,说下我的方 ...

  4. hdu1828 线段树扫描线求矩形面积的周长

    题意:       给你n个矩形,问你这n个矩形所围成的图形的周长是多少. 思路:       线段树的扫描线简单应用,这个题目我用的方法比较笨,就是扫描两次,上下扫描,求出多边形的上下边长和,然后同 ...

  5. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  6. HDU 1542"Atlantis"(线段树+扫描线求矩形面积并)

    传送门 •题意 给你 n 矩形,每个矩形给出你 $(x_1,y_1),(x_2,y_2)$ 分别表示这个矩形的左下角和右上角坐标: 让你求这 n 个矩形并的面积: 其中 $x \leq 10^{5} ...

  7. poj 1177 --- Picture(线段树+扫描线 求矩形并的周长)

    题目链接 Description A number of rectangular posters, photographs and other pictures of the same shape a ...

  8. hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]

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

  9. hdu 1542(线段树+扫描线 求矩形相交面积)

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

随机推荐

  1. instanceof的用法①

    public class typeof1{ private String a="zzw"; public void instance(){ if(a instanceof Stri ...

  2. C## 输出Hello world

    首先新建一个项目 然后在文件D:\C##Obj\HelloWorld\HelloWorld\Program.cs using System; using System.Collections.Gene ...

  3. 关于C#中的DateTime类型的技巧

    * datetime.now.tostring()方法默认的你是无法得到全部的时间的格式的,只能得到日期,得不到具体时间,如果要具体时间,就应该使用 datetime的tostring()重载,dat ...

  4. eclipse-自动注释

    在eclipse中自动添加'注释'的快捷键是'Alt+Shift+J',可以在 MyEclipse中的 Java->Code Style->Code Template->Commen ...

  5. recursive - simple screenshot but detail principle.

    the code below demonstates the principle of the'recursive-call' that the programing beginner may be ...

  6. For and While loop choice.

    /* Difference between 'for' and 'while'. We can transform everything between 'for' and 'while'. if t ...

  7. NSDate和NSString的转换及判定是昨天,今天,明天

    用于uidate,picker.. +(NSDate*) convertDateFromString:(NSString*)uiDate{    NSDateFormatter *formatter ...

  8. iOS 原生二维码扫描(可限制扫描区域)

    篇文章的主要原因不是展示如何使用  AVFoundation 来进行二维码扫描,更主要的是限制扫描二维码的范围.(因为默认的是全屏扫描) 项目遇到扫描二维码的功能需求,这里我放弃了使用三方库,而采用了 ...

  9. 【转】 NSString什么时候用copy,什么时候用strong

    原文: http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是copy,那copy与strong的情况下到底有 ...

  10. 《Python 二三事》——python学习必看(转载)

        面向初学者介绍Python相关的一些工具,以及可能遇到的常见问题. 原文出处 原文作者:八八年出生的男性,互联网上常用id是 jagttt .目前正从事 IT 行业的工作.业余爱好是动漫游加电 ...