题意:

求矩形覆盖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. [转] Initial Impressions on GraphQL & Relay

    https://kadira.io/blog/graphql/initial-impression-on-relay-and-graphql http://graphql.org/blog/subsc ...

  2. 隐藏iframe边框

    关于iframe在ie浏览器中边框隐藏的问题,一直困惑着我.其实就是一个很简单的办法,主要设置一个属性即可解决,方法如下: <iframe frameborder="0"&g ...

  3. css考核点整理(二)-css层叠机制

    css层叠机制 外边距重叠就是margin-collapse. 在CSS当中,相邻的两个盒子(可能是兄弟关系也可能是祖先关系)的外边距可以结合成一个单独的外边距.这种合并外边距的方式被称为折叠,并且因 ...

  4. instanceof的用法②

    其实这个问题以前也困扰过我.我个人理解的一个应用场合就是,当你拿到一个对象的引用时(例如参数), 你可能需要判断这个引用真正指向的类.所以你需要从该类继承树的最底层开始,使用instanceof操作符 ...

  5. Java 获取字符串中第N次出现的字符位置

    public static int getCharacterPosition(String string){    //这里是获取"/"符号的位置    Matcher slash ...

  6. What and where are the stack and heap?

    The stack is the memory set aside as scratch space for a thread of execution. When a function is cal ...

  7. iOS CGContextRef 画图小结

    CGContextRef context = UIGraphicsGetCurrentContext(); //设置上下文 //画一条线 CGContextSetStrokeColorWithColo ...

  8. 通过C# 打开一个应用程序

    System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo(); //设置外部程序名 Info ...

  9. web一点小结

    1, AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJAX ...

  10. const关键字与指针

    const与指针在一起的几种情况. const int *p1; //表示p1本身不是const,指向的变量是const. const *int p2; //语法错误 int const *p3; / ...