codeforce div 377
#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的更多相关文章
- CodeForce Div 2 C. Masha and two friends
题目链接: http://codeforces.com/contest/1080/problem/C 思路:双向延长两个矩形方块的4边,会形成一个被分割为9块的更大立方体. 计算所有的9个方框.方框中 ...
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- Codeforces Round #377 (Div. 2)
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- 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 ...
- Codeforces Round #377 (Div. 2) C. Sanatorium 水题
C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- UICollectionView 图片横向滑动居中偏移量的解决
1.在使用UICollectionView 来显示横向滑动图片的时候,cell与cell之间有间隙,每次滑动后cell都会向左偏移,在使用过这两个方法才解决每次向左偏移的部分. 2.使用方法前不要开启 ...
- Candy Store
Candy Store Time Limit: 30000ms, Special Time Limit:75000ms, Memory Limit:65536KB Total submit users ...
- php部分---注册审核
用户界面: 1.登录界面,用户填写相关信息 <form action="dengluchuli.php" method="post"> <di ...
- 用多itemtype的具有addHeaderView的recyclerview,还是scrollview?
如果一个复杂的布局,1,轮播图,2,广告图,3,带标题的list,4,gridview布局,各种不同的布局 在最外层套一个scrollview,里面list 用for循环addView,gridvie ...
- [linux] FastDFS访问文件,400 Bad Request
linux 安装nginx,FastDFS后,启动访问指定文件出错, 文件名称格式化错误. 解决办法: vi /etc/fdfs/mod_fastdfs.conf 将 url_have_group_n ...
- 各种数据分析图demo
极地蛛网图:http://www.hcharts.cn/demo/index.php?p=61 各种数据分析图demo: http://www.hcharts.cn/demo/index.php?p= ...
- 解决php的“It is not safe to rely on the system’s timezone settings”问题
PHP调试的时候出现了警告: It is not safe to rely on the system解决方法,其实就是时区设置不正确造成的,本文提供了3种方法来解决这个问题. 实 际上,从PHP 5 ...
- java 线程的堵塞
//线程的阻塞 // //线程 class xc1 implements Runnable{ public void run(){ for(int i=1;i<=30;i++){ System. ...
- Eclipse集成javap查看字节码
分析java语言特性的一个好帮手是使用javap工具查看java编译后的字节码,楼主今天在学习java泛型中的桥方法时遇到一些不解,想到javap这个好工具可以帮助解答一些疑惑,索性就捣鼓如何在ecl ...
- RESTClient使用
RESTClient使用