#include <bits/stdc++.h>
using namespace std; #define pb push_back
#define lb lower_bound
#define ull unsigned ll
#define gcd(a,b) __gcd(a,b)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define ll long long
#define mp make_pair
//#define pi acos(-1) #define mod 1000000007
#define inf (1LL<<31)-1 map<int,vector<pii> > X,Y;
vector<pair<int,pii> > V; const int mx = 200005;
int tree[mx], pos[mx],N; int getPos(int n)
{
return (int) (lb(pos,pos+N,n)-pos) + 1;
} int update(int idx,int val)
{
while(idx<=N)
{
tree[idx] += val;
idx += (idx&-idx);
}
return 0;
} int sum(int idx)
{
int res = 0;
while(idx>0)
{
res += tree[idx];
idx -= (idx&-idx);
}
return res;
} int main()
{
int i,j,k,n;
scanf("%d",&n);
int x1,y1,x2,y2;
for(i=0;i<n;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
if(x1==x2) Y[x1].pb(mp(y1,y2));
else X[y1].pb(mp(x1,x2));
pos[N++] = y1;
pos[N++] = y2;
}
sort(pos,pos+N);
N = (int) (unique(pos,pos+N)-pos); map<int,vector<pii> > :: iterator it; ll ans = 0;
for(it=X.begin();it!=X.end();it++)
{
vector<pii>& vt = it -> second;
sort(all(vt));
int y = (it -> first);
int x1 = vt[0].first;
int x2 = vt[0].second;
int sz = vt.size();
for(i=1;i<sz;i++)
{
if(x2<vt[i].first)
{
ans += (x2-x1+1);
V.pb(mp(x1,mp(-1,y)));
V.pb(mp(x2+1,mp(1,y)));
x1 = vt[i].first;
x2 = vt[i].second;
}
else x2 = max(x2,vt[i].second);
}
ans += (x2-x1+1);
V.pb(mp(x1,mp(-1,y)));
V.pb(mp(x2+1,mp(1,y)));
} int m = V.size(), p = 0;
sort(all(V));
for(it=Y.begin();it!=Y.end();it++)
{
vector<pii>& vt = it -> second;
sort(all(vt));
int x = (it -> first); while(p<m&&x>=V[p].first)
{
int t1 = V[p].second.first;
int t2 = V[p].second.second;
t2 = getPos(t2);
update(t2,-t1);
p++;
} int y1 = vt[0].first;
int y2 = vt[0].second;
int sz = vt.size();
for(i=1;i<sz;i++)
{
if(y2<vt[i].first)
{
ans += (y2-y1+1);
y2 = getPos(y2);
y1 = getPos(y1);
ans -= sum(y2) - sum(y1-1);
y2 = vt[i].second;
y1 = vt[i].first;
}
else y2 = max(y2,vt[i].second);
}
ans += (y2-y1+1);
y2 = getPos(y2);
y1 = getPos(y1);
ans -= sum(y2) - sum(y1-1);
}
cout << ans << endl;
}

  

codeforce div 377的更多相关文章

  1. CodeForce Div 2 C. Masha and two friends

    题目链接: http://codeforces.com/contest/1080/problem/C 思路:双向延长两个矩形方块的4边,会形成一个被分割为9块的更大立方体. 计算所有的9个方框.方框中 ...

  2. Codeforces Round #377 (Div. 2) D. Exams

    Codeforces Round #377 (Div. 2) D. Exams    题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...

  3. Codeforces Round #377 (Div. 2)

    #include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...

  4. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  5. Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)

     传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...

  6. Codeforces Round #377 (Div. 2) D. Exams(二分答案)

    D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...

  7. Codeforces Round #377 (Div. 2)D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...

  8. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  9. Codeforces Round #377 (Div. 2) C. Sanatorium 水题

    C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 启动运行下载gradle速度太慢,手动添加

    启动运行下载gradle速度太慢,并且容易卡死(感谢群友ˋ狠ㄨ得意提供支持)---国内网络访问地址 我们经常运行项目的时候会需要进行下载gradle,不过由于网络或者和谐的问题经常下载需要花很长时间或 ...

  2. Java笔记1-Java相关概念和如何实现跨平台

    一.Java相关概念 1.Java语言的核心特点跨平台面向对象 2.Java的历史版本JDK1.0,JDK1.1,JDK1.2....JDK5.0,JDK6.0,JDK7.0,JDK8.0 注意:JD ...

  3. Python中reactor,factory,protocol

    最为简单的情况下,除了了解清reactor的简单使用,你还要了解Protocol和Factory.它们最终都会由reactor的侦听建立和run来统一调度起来. 建立服务器的第一个要解决的问题就是服务 ...

  4. linux 给文件夹权限

    用的thinkphp3.2的框架,在本地运行没有问题,部署到服务器上(基于centos的LAMP环境)即报错_STORAGE_WRITE_ERROR_:./Application/Runtime/Ca ...

  5. Linux安装gcc编译器详解

    本人使用的是CentOS 6.5 64位系统,由于在安装系统的时候并没有勾选安装gcc编译器,因此需要自行安装gcc编译器. 使用yum安装gcc 对于配备了yum的Linux发行版而言,安装gcc编 ...

  6. Mysql 自定义HASH索引带来的巨大性能提升----[挖坑篇]

    有这样一个业务场景,需要在2个表里比较存在于A表,不存在于B表的数据.表结构如下: T_SETTINGS_BACKUP | CREATE TABLE `T_SETTINGS_BACKUP` ( `FI ...

  7. 【巩固】CSS3的animation基础

    终于结束了最后css3的一节课,关于animation的使用,其实之前已经用过一次.大致要了解的就是,关于如何让动画停在最后一帧的方法.视频里有提到过css3出了个新的样式可以实现,但是老师没有记住, ...

  8. gerrit 修改前一次提交的方法(转载)

    From:http://sinojelly.sinaapp.com/2011/08/git-changes-submitted-by-the-previous-method-pay-special-a ...

  9. Linux定时任务系统 Cron

    运行计划任务时:service crond restart提示:crond: unrecognized service安装计划任务:yum -y install vixie-cron 另外附计划任务的 ...

  10. jQuery - 疑惑

    设置内容和属性:http://www.runoob.com/jquery/jquery-dom-set.html