https://vjudge.net/problem/ZOJ-3540

错误记录:

扫描线没有考虑到同一行的要删除在前,加入在后;由于用了特殊的方式所以想当然以为不需要考虑这个问题

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
struct Q
{
ll x1,y1,x2,y2;
}q[];
ll w,h,n,m;
struct Q2
{
ll x1,x2,y,type;
}qt[];
ll t1[];
bool operator<(const Q2 &a,const Q2 &b)
{
return a.y<b.y||(a.y==b.y&&a.type<b.type);
}
ll qn,ta,ans;
set<pi> s;
set<pi>::iterator it;
int main()
{
ll i,r,tx,ty;
while(scanf("%lld%lld%lld%lld",&w,&h,&n,&m)==)
{
ans=; for(i=;i<=n;i++) scanf("%lld%lld%lld%lld",&q[i].x1,&q[i].y1,&q[i].x2,&q[i].y2); qn=;
s.clear();s.insert(mp(-,));s.insert(mp(w+,w+));
for(i=;i<=n;i++)
{
++qn;qt[qn].x1=q[i].x1;qt[qn].x2=q[i].x2;qt[qn].y=q[i].y1;qt[qn].type=;
++qn;qt[qn].x1=q[i].x1;qt[qn].x2=q[i].x2;qt[qn].y=q[i].y2+;qt[qn].type=;
}
sort(qt+,qt+qn+);
for(i=;i<=qn;i++) t1[i]=qt[i].y;
t1[]=qn;
t1[++t1[]]=;
t1[++t1[]]=h+;
sort(t1+,t1+t1[]+);t1[]=unique(t1+,t1+t1[]+)-t1-;
r=;ta=max(w-m+,0ll);
for(i=;i<t1[];i++)
{
while(r+<=qn&&qt[r+].y<=t1[i])
{
r++;
if(qt[r].type==)
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=it->first;ty=(--it)->second;
ta-=max(tx-ty-m,0ll);
ta+=max(qt[r].x1-ty-m,0ll);
ta+=max(tx-qt[r].x2-m,0ll);
s.insert(mp(qt[r].x1,qt[r].x2));
}
else
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=(++it)->first;--it;ty=(--it)->second;
ta-=max(qt[r].x1-ty-m,0ll);
ta-=max(tx-qt[r].x2-m,0ll);
ta+=max(tx-ty-m,0ll);
s.erase(mp(qt[r].x1,qt[r].x2));
}
}
ans+=ta*(t1[i+]-t1[i]);
} qn=;
s.clear();s.insert(mp(-,));s.insert(mp(h+,h+));
for(i=;i<=n;i++)
{
++qn;qt[qn].x1=q[i].y1;qt[qn].x2=q[i].y2;qt[qn].y=q[i].x1;qt[qn].type=;
++qn;qt[qn].x1=q[i].y1;qt[qn].x2=q[i].y2;qt[qn].y=q[i].x2+;qt[qn].type=;
}
sort(qt+,qt+qn+);
for(i=;i<=qn;i++) t1[i]=qt[i].y;
t1[]=qn;
t1[++t1[]]=;
t1[++t1[]]=w+;
sort(t1+,t1+t1[]+);t1[]=unique(t1+,t1+t1[]+)-t1-;
r=;ta=max(h-m+,0ll);
for(i=;i<t1[];i++)
{
while(r+<=qn&&qt[r+].y<=t1[i])
{
r++;
if(qt[r].type==)
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=it->first;ty=(--it)->second;
ta-=max(tx-ty-m,0ll);
ta+=max(qt[r].x1-ty-m,0ll);
ta+=max(tx-qt[r].x2-m,0ll);
s.insert(mp(qt[r].x1,qt[r].x2));
}
else
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=(++it)->first;--it;ty=(--it)->second;
ta-=max(qt[r].x1-ty-m,0ll);
ta-=max(tx-qt[r].x2-m,0ll);
ta+=max(tx-ty-m,0ll);
s.erase(mp(qt[r].x1,qt[r].x2));
}
}
ans+=ta*(t1[i+]-t1[i]);
} if(m==) ans/=;
printf("%lld\n",ans);
}
return ;
}

Adding New Machine ZOJ - 3540的更多相关文章

  1. HDU 4052 Adding New Machine(矩形面积并)

    Adding New Machine Problem Description Incredible Crazily Progressing Company (ICPC) suffered a lot ...

  2. UVA1492 - Adding New Machine(扫描线)

    UVA1492 - Adding New Machine(扫描线) option=com_onlinejudge&Itemid=8&page=show_problem&cate ...

  3. HDU 4052 Adding New Machine (线段树+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4052 初始给你w*h的矩阵,给你n个矩形(互不相交),按这些矩形尺寸把初始的矩形扣掉,形成一个新的'矩 ...

  4. 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)

    转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...

  5. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  6. hdu 4052 线段树扫描线、奇特处理

    Adding New Machine Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. QEMU, a Fast and Portable Dynamic Translator-Fabrice Bellard-翻译

    Abstract We present the internals of QEMU, a fast machine emulator using an original portable dynami ...

  8. HZNU Training 4 for Zhejiang Provincial Collegiate Programming Contest 2019

    今日这场比赛我们准备的题比较全面,二分+数论+最短路+计算几何+dp+思维+签到题等.有较难的防AK题,也有简单的签到题.为大家准备了一份题解和AC代码. A - Meeting with Alien ...

  9. zoj 3805 Machine

    Machine Time Limit: 2 Seconds      Memory Limit: 65536 KB In a typical assembly line, machines are c ...

随机推荐

  1. TC SRM 583 DIV 2

    做了俩,rating涨了80.第二个题是关于身份证的模拟题,写的时间比较长,但是我认真检查了... 第三个题是最短路,今天写了写,写的很繁琐,写的很多错. #include <cstring&g ...

  2. java线程阻塞(sleep,suspend,resume,yield,wait,notify)

    为了解决对共享存储区的访问冲突,Java 引入了同步机制,现在让我们来考察多个线程对共享资源的访问,显然同步机制已经不够了,因为在任意时刻所要求的资源不一定已经准备好了被访问,反过来,同一时刻准备好了 ...

  3. InspectIT_EUM 实现原理概述

    在Git上查看 InspectIT 实现原理概述: 实现原理详解:  1.jsAgent如何注入到浏览器 通过ASM框架修改HttpService.service()方法,加入相关逻辑,对每一个Htt ...

  4. VS 预先生成事件命令

    宏 说明 $(ConfigurationName) 当前项目配置的名称(例如,“Debug|Any CPU”). $(OutDir) 输出文件目录的路径,相对于项目目录.这解析为“输出目录”属性的值. ...

  5. Mac JDK 多版本共存

    1.    安装各JDK版本,安装后通过Java -version检测是否安装好    2.    打开~/.bash_profile,没有的话创建    vim ~/.bash_profile   ...

  6. bfs 邻接表

    #include<stdio.h> #include<stdlib.h> #include<string.h> struct node { int date; st ...

  7. js操作创建和操作外部样式的例子

    兼容IE8及以上的IE浏览器1. [代码][HTML]代码 <!DOCTYPE html><html lang="en">    <head>  ...

  8. HDU 1711(KMP)字符串匹配

    链接  HDU 1711 Number Sequence KMP 算法 我以自己理解写的,写的不对,不明白的地方海王子出来,一起共同学习: 字符串匹配 就是KMP,一般思想,用一个for循环找开头   ...

  9. [Selenium] Actions.doubleClick

    WebElement el = page.getTable_AssetMixesName().get(index); Actions action = new Actions(driver); act ...

  10. 微信小程序在线支付功能使用总结

    最近需要在微信小程序中用到在线支付功能,于是看了一下官方的文档,发现要在小程序里实现微信支付还是很方便的,如果你以前开发过服务号下的微信支付,那么你会发现其实小程序里的微信支付和服务号里的开发过程如出 ...