| 记录编号 |
156062 |
评测结果 |
AAAAA |
| 题目名称 |
263.[IOI 1998] 矩形周长 |
最终得分 |
100 |
| 用户昵称 |
天一阁 |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
0.010 s |
| 提交时间 |
2015-04-01 19:44:33 |
内存使用 |
7.18 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define Maxn 200010
#define l(x) (x<<1)
#define r(x) (x<<1|1)
using namespace std;
struct node{
int lx,rx,h,s;
inline bool operator<(const node& a)const{
if(h==a.h) return s>a.s;
return h<a.h;
}
}line[Maxn];
int sum[Maxn],n,tot=0,cov[Maxn],lbd[Maxn],rbd[Maxn];
int cnt[Maxn];
int Abs(int x){
if(x<0) return -x;
return x;
}
void update(int o,int l,int r){
if(cov[o]){
lbd[o]=rbd[o]=1;
sum[o]=r-l+1; cnt[o]=2;
}
else if(l==r) sum[o]=cnt[o]=lbd[o]=rbd[o]=0;
else{
lbd[o]=lbd[l(o)]; rbd[o]=rbd[r(o)];
sum[o]=sum[l(o)]+sum[r(o)];
cnt[o]=cnt[l(o)]+cnt[r(o)];
if(rbd[l(o)] && lbd[r(o)]) cnt[o]-=2;
}
}
void change(int o,int l,int r,int ql,int qr,int qv){
if(ql<=l&&r<=qr){
cov[o]+=qv; update(o,l,r);
return;
}
int mid=(l+r)>>1;
if(ql<=mid) change(l(o),l,mid,ql,qr,qv);
if(mid<qr) change(r(o),mid+1,r,ql,qr,qv);
update(o,l,r);
}
int x0,x1,y0,y1,ans=0,L=10000,R=-10000;
int main(){
freopen("picture.in","r",stdin);
freopen("picture.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
line[++tot]=(node){x0,x1,y0,1};
line[++tot]=(node){x0,x1,y1,-1};
L=min(L,x0); R=max(R,x1);
}
sort(line+1,line+tot+1);
int last=0;
for(int i=1;i<=tot;i++){
change(1,L,R,line[i].lx,line[i].rx-1,line[i].s);
ans+=cnt[1]*(line[i+1].h-line[i].h);
ans+=Abs(sum[1]-last); last=sum[1];
}
printf("%d\n",ans);
return 0;
}