给你一坨矩形,问这些矩形组成的所有多边形的周长之和。

  分别求竖着的边和横着的边。

  离散化后线段树,维护当前行(或者列)有多少没在多边形里的,添加矩形就变成添加、删除线段。

  每次加线段或删线段时累加一下贡献(加线段时的贡献就是加完后那条线段里有多少个位置变成在多边形里,删线段时的贡献就是删完后有多少个位置变成不在多边形里)。

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
#define ull unsigned long long
#define d double
using namespace std;
const int maxn=,mxnode=maxn*;
struct zs{int h,l,r;bool add;}b[maxn];int n1;
struct mat{int x1,y1,x2,y2;}a[];
int lc[mxnode],rc[mxnode],mn[mxnode],num[mxnode],add[mxnode],tot,MX;
int i,j,k,n,m,L,R,V;
ll ans; int ra,fh;char rx;
inline int read(){
rx=getchar(),ra=,fh=;
while((rx<''||rx>'')&&rx!='-')rx=getchar();
if(rx=='-')fh=-,rx=getchar();
while(rx>=''&&rx<='')ra*=,ra+=rx-,rx=getchar();return ra*fh;
} inline void ins(int &x,int l){x=++tot,mn[x]=add[x]=,num[x]=l;}
inline void upd(int x){
int l=lc[x],r=rc[x];
if(mn[l]>mn[r])swap(l,r);
if(mn[l]==mn[r])mn[x]=mn[l]+add[x],num[x]=num[l]+num[r];
else mn[x]=mn[l]+add[x],num[x]=num[l];
}
void insert(int x,int a,int b){
// printf("insert:%d--%d %d-----%d\n",a,b,L,R);
if(L<=a&&R>=b){add[x]+=V,mn[x]+=V;return;}
int mid=a+b>>;
if(!lc[x])ins(lc[x],mid-a+);if(!rc[x])ins(rc[x],b-mid);
if(L<=mid)insert(lc[x],a,mid);
if(R>mid)insert(rc[x],mid+,b);
upd(x);//printf("%d--%d mn:%d num:%d\n",a,b,mn[x],num[x]);
} inline int get0(){return mn[]!=?:num[];}
bool cmp(zs a,zs b){return a.h<b.h||(a.h==b.h&&a.add);}
inline void calc(){
int i;
sort(b+,b++n1,cmp);
for(i=;i<=tot;i++)lc[i]=rc[i]=;tot=,mn[]=add[]=,num[]=MX;
for(i=;i<=n1;i++){
L=b[i].l,R=b[i].r;
if(b[i].add)ans+=get0(),V=,insert(,,MX),ans-=get0();
else ans-=get0(),V=-,insert(,,MX),ans+=get0();//printf("num0:%d mn:%d\n",get0(),mn[1]);
}//printf(" ans:%d\n",ans);
} inline int abs1(int x){return x<?-x:x;}
inline int max(int a,int b){return a>b?a:b;}
int main(){
n=read();int tmp;
for(i=;i<=n;i++){
a[i].x1=read(),a[i].y1=read(),a[i].x2=read()-,a[i].y2=read()-;
tmp=max(max(abs1(a[i].x1),abs1(a[i].x2)),max(abs1(a[i].y1),abs1(a[i].y2)));
if(tmp>MX)MX=tmp;
}
for(i=;i<=n;i++)a[i].x1+=MX+,a[i].x2+=MX+,a[i].y1+=MX+,a[i].y2+=MX+;
MX=MX<<|;
n1=;
for(i=;i<=n;i++)
b[++n1]=(zs){a[i].x1,a[i].y1,a[i].y2,},
b[++n1]=(zs){a[i].x2+,a[i].y1,a[i].y2,};
calc();
n1=;
for(i=;i<=n;i++)
b[++n1]=(zs){a[i].y1,a[i].x1,a[i].x2,},
b[++n1]=(zs){a[i].y2+,a[i].x1,a[i].x2,};
calc();
printf("%lld\n",ans);
}

[51nod1206]Picture的更多相关文章

  1. 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?

    复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...

  2. MFC Picture控件加载图片

    CStatic *pPic = (CStatic*)GetDlgItem(IDC_PICTURE); CBitmap bitmap; bitmap.LoadBitmapW(IDB_BITMAP2); ...

  3. [POJ1177]Picture

    [POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...

  4. USACO 5.5 Picture(周长并)

    POJ最近做过的原题. /* ID: cuizhe LANG: C++ TASK: picture */ #include <cstdio> #include <cstring> ...

  5. 彩色照片转换为黑白照片(Color image converted to black and white picture)

    This blog will be talking about the color image converted to black and white picture. The project st ...

  6. HDU 1828 Picture(线段树扫描线求周长)

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

  7. don't forget the bigger picture

    Imagine a circle that contains all of human knowledge: By the time you finish elementary school, you ...

  8. A Complete Guide to the <Picture> Element

    If you’ve ever struggled building responsive websites, this post is for you. It’s part of a series o ...

  9. HDUOJ-----(1162)Eddy's picture(最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. python访问http的GET/POST

    版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/7562295.html 作者:窗户 Q ...

  2. chmod 命令详解

    chmod 作用:修改目录或文件权限(= 赋值不管存在与否, + 增加权限)符号链接的权限无法变更, 如果用户对符号链接修改权限, 其改变会作用在被链接的原始文件. 参数: -R: 递归修改处理 -v ...

  3. sql server 2012 新知识-序列

    今天聊一聊sql 2012 上的新功能-----序列 按我的理解,它就是为了实现全局性的唯一标识,按sql server 以前的版本,想对一张表标识很简单,比如identity,但如果要对某几张有业务 ...

  4. Golang 网络爬虫框架gocolly/colly 四

    Golang 网络爬虫框架gocolly/colly 四 爬虫靠演技,表演得越像浏览器,抓取数据越容易,这是我多年爬虫经验的感悟.回顾下个人的爬虫经历,共分三个阶段:第一阶段,09年左右开始接触爬虫, ...

  5. ubuntu 安装 pythonenv

    This will get you going with the latest version of pyenv and make it easy to fork and contribute any ...

  6. 命令行执行Django脚本的方法

    update.py import os import sys import django sys.path.append(r'C:\Users\Administrator\PycharmProject ...

  7. PHP使用ueditor上传配置

    引入 按照ueditor官网demo, 引入好ueditor之后, 默认是不能进行上传操作的 在上传时,在上传时会有如下图提示 配置上传 在editor/php目录下,有一个config.json文件 ...

  8. java多线程(六)-线程的状态和常用的方法

    一个线程可以处于以下几种状态之一: (1) 新建(new):当线程被创建时,它只会短暂的处于这种状态,此时它已经获得了必须的系统资源,并执行了初始化,该线程已经有资格获取cpu时间了,之后它将转化为可 ...

  9. 淘宝NPM源的使用

    npm作为国外的node仓库安装工具,自然会受到我大长城防火墙的干扰,国内用户在安装相关的资源的时候,会出现安装失败,以及速度很慢的情况.为了解决npm安装的问题,国内出现了很多npm的镜像网址,ta ...

  10. checkbox对齐-复选框图标

    checkbox对齐-复选框图标 一般开发过程中,我们直接使用<input type="checkbox"/>这样出现的复选框,设计师一般都说不好看 而让我们按照设计稿 ...