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 ...
随机推荐
- Directory的GetFiles方法
想实现一个功能 :比如多个业务审批流程公用一个审批表的时候,有一个提示审批信息的页面 ,点击该页面不同的业务审批流程记录的时候,跳转到不同业务流程的详细显示界面 额 这样说 貌似以后我自己也看不明白 ...
- bootstrap-8
基本按钮: bootstrap框架V3.x版本的基本按钮和V2.x版本的基本按钮一样,都是通过类名.btn来实现,不同的是V3.x版本要简约很多,去除V2.x版本中的大量的CSS3的部分特效. 默认按 ...
- JSP知识点汇总
有几种方法可以实现服务器内部跳转? 使用request对象提供的方法:request.getRequestDispatcher(String URI).forward(ServletRequest r ...
- 1、C#入门第一课
C# 读作C Sharp,所以程序文件的扩展名为.cs 新建项目-窗体应用程序 所谓的Visual C#就是指的可视化编程,主要在设计窗口布置好自己的控件(一些具有一定功能的小部件,例如如可以点击的按 ...
- oracle审计详解-转
http://blog.chinaunix.net/u2/66903/showart_2082884.htmlOracle使用大量不同的审计方法来监控使用何种权限,以及访问哪些对象.审计不会防止使用这 ...
- <script>标签应该放到</body>标签之前
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:贺师俊 链接:http://www.zhihu.com/question/20027966/answer/13727164 ...
- 033. asp.netWeb用户控件之二将页面转换成web控件和使用Web控件显示热点新闻
访问Web用户控件的属性 ASP.NET提供的各种服务器控件都有其自身的属性和方法,程序开发人员可以灵活地使用服务器控件中的属性和方法开发程序.在用户控件中,程序开发人员也可以自行定义各种属性和方法, ...
- Windows xp IIS显示403错误解决方案
XP的IIS很烦人,很多限制. 最近一客户用XP安装IIS,总提示:403.9 错误 连接的用户过多 解决方案: 1)安装IIS配置工具 下载地址:http://download.microsoft. ...
- 【python】模块作用域
作用域 在一个模块中,我们可能会定义很多函数和变量,但有的函数和变量我们希望给别人使用,有的函数和变量我们希望仅仅在模块内部使用.在Python中,是通过_前缀来实现的. 类似_xxx和__xxx这样 ...
- JSONP理解和使用
一.代码使用: $.ajax({ async:false, url: http://跨域的dns, type: "GET", dataType: 'jsonp'}); 二.理解: ...