#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. Kaiju: Fast and sensitive taxonomic classification for metagenomics

    Kaiju: Fast and sensitive taxonomic classification for  metagenomics   问题描述:However, nucleotide comp ...

  2. iTunesConnect进行App转移2-官方说明

    Can I transfer an app to another developer's iTunes Connect account? Yes, you can transfer your app ...

  3. 对于EL表达式和ONGL表达式区别的相关理解

    java程序跑起来之后,会有一个内存空间分配出来,存入用到的值,这个值的周围就是上下文空间,而九大内置对象等,都在这个值的周围放着,像这样: el 就只能获取value stack 周围 的数据,va ...

  4. 数迹学——Asp.Net MVC4入门指南(2):添加一个控制器

    自嘲一下......万事还是得从官方的入门开始 由于找不到适合新新手的MVC入门实例所以回过头来做一下微软的 <Asp.Net MVC4入门指南>. 只有把自己放在太阳下暴晒,才知道自己有 ...

  5. 公钥与私钥,HTTPS详解

    1.公钥与私钥原理1)鲍勃有两把钥匙,一把是公钥,另一把是私钥2)鲍勃把公钥送给他的朋友们----帕蒂.道格.苏珊----每人一把.3)苏珊要给鲍勃写一封保密的信.她写完后用鲍勃的公钥加密,就可以达到 ...

  6. Spring JSR-250注解

    Java EE5中引入了“Java平台的公共注解(Common Annotations for the Java Platform)”,而且该公共注解从Java SE 6一开始就被包含其中. 2006 ...

  7. 一些关于HTTP协议、表单和……的备忘

    几个概念 Ajax是一种技术.asp.net是一个库.json是一种数据格式.jquery是js的库(源码).ror是ruby on rails.python,就是python.Ajax和AJAX,后 ...

  8. angular+bootstrap+MVC 之二,模态窗

    本例实现一个bootstrap的模态窗 1.HTML代码 <!doctype html> <!--suppress ALL --> <html ng-app=" ...

  9. 在AD转换中的过采样和噪声形成

    1. 直接量化的过采样AD转换 此类系统的模型可以用下图表示. 图中xa(t)是输入信号,e(t)是量化引入的噪声,xd[n]是最终得到的数字信号,包含分量xda和xde. 对于M倍过采样,信号与量化 ...

  10. jQuery使用load方法加载其他文档内容

    A文档载入B文档的内容,并且通过JQ操作被引入到A文档中的元素 A文档 (index.html): <!DOCTYPE html> <html lang="en" ...