CodeForces 610D Vika and Segments
模板题,矩形面积并
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 220000
#define lson l,m,rt << 1
#define rson m + 1,r,rt << 1 | 1
#define eps 1e-15
using namespace std;
struct seg
{
double l,r,y;
int sign;
seg() {}
seg(double a, double b, double h, int s): l(a), r(b),y(h),sign(s) {}
bool operator < (const seg &cmp) const
{
if(cmp.y == y) return sign > cmp.sign;
return y < cmp.y;
}
} p[ (maxn << )+ ]; double sum[ (maxn << )+ ];
int cnt[ (maxn << ) + ]; double X[ (maxn << ) + ]; void push_up(int rt,int l, int r)
{
if(cnt[rt]) sum[rt] = X[r + ] - X[l]; else if(l == r) sum[rt] = 0.0; else sum[rt] = sum[rt << ] + sum[rt << | ];
}
void update(int L, int R, int cc, int l , int r, int rt)
{
if(L <= l && r <= R)
{
cnt[rt] += cc;
push_up(rt,l,r);
return ;
}
int m = (l + r) >> ;
if(L <= m) update(L,R,cc,lson);
if(R > m) update(L,R,cc,rson);
push_up(rt,l,r);
}
int bin(int low, int high, double key)
{
int mid ;
while(low < high)
{
mid = (low + high) >> ;
if(X[mid] < key ) low = mid + ;
else high = mid;
}
return low;
}
int main()
{
int n,m,k,pp,ca = ;
double a,b,c,d,ret;
while(scanf("%d",&n) != EOF && n)
{
memset(sum,,sizeof(sum));
memset(cnt,,sizeof(cnt));
m = k = ;
ret = 0.0;
pp = ; for(int i = ; i < n; i ++)
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
if(b==d)
{
if(a>c) swap(a,c);
}
else if(a==c)
{
if(b>d) swap(b,d);
}
c++;
d++;
X[m ++] = a;
X[m ++] = c; p[k ++] = seg(a,c,b,); p[k ++] = seg(a,c,d,-);
}
sort(X,X + m);
sort(p,p + k); for(int i = ; i < m; i ++)
if(X[i - ] != X[i])
{
X[pp ++] = X[i];
} pp --;
for(int i = ; i < k - ; i ++)
{
int l = bin(, pp , p[i].l);
int r = bin(, pp , p[i].r) - ;
if(l <= r) update(l,r,p[i].sign,,pp,);
ret += (p[i + ].y - p[i].y) * sum[];
}
printf("%.0f\n",ret);
}
return ;
}
CodeForces 610D Vika and Segments的更多相关文章
- Codeforces 610D Vika and Segments 线段树+离散化+扫描线
可以转变成上一题(hdu1542)的形式,把每条线段变成宽为1的矩形,求矩形面积并 要注意的就是转化为右下角的点需要x+1,y-1,画一条线就能看出来了 #include<bits/stdc++ ...
- 610D - Vika and Segments(线段树+扫描线+离散化)
扫描线:http://www.cnblogs.com/scau20110726/archive/2013/04/12/3016765.html 看图,图中的数字是横坐标离散后对应的下标,计算时左端点不 ...
- codeforces 610D D. Vika and Segments(离散化+线段树+扫描线算法)
题目链接: D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
- Codeforces Round #337 Vika and Segments
D. Vika and Segments time limit per test: 2 seconds memory limit per test: 256 megabytes input ...
- 【20.51%】【codeforces 610D】Vika and Segments
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...
- Vika and Segments - CF610D
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-d ...
随机推荐
- 删除cygwin
由于cygwin 学习了linux 的用户所有者的方式,要删除有一定困难. 所以要右击 然后点 获取管理员所有权 几分钟之后 就可以删了
- oomph
http://blog.csdn.net/u011004037/article/details/45679573 这么好个功能起了这么操蛋个名字害得老子一直不知道他干啥的
- sql server字段是逗号分割的id,关联明细表查询
有时候一张表的一个字段是以逗号分割的一个字符串,分割的数字是明细表的主键id. 关联明细表查询可以这样做: ) ) --这是把areanos字段赋值给@areanos变量 set @areanos=' ...
- HDU 2018 undefined
题目思路:完全背包,dp[i][j]代表,砍j只怪,用i点疲劳最多能获得的经验值. 和平常的完全背包不一样的是多了一个限制条件:最多只砍S只怪,所以我们应该多一重循环来q:for 1->S,代表 ...
- ngnix配置文件
使用nginx最大的好处就是负载均衡. #设定负载均衡的服务器列表 upstream service{ server 10.4.29.174:7477; } server { ...
- oracle的row_number()和rownum
row_number() 函数和rownum的介绍: 1.row_number() 方法的格式: row_number()over([partition by col1] order by col2) ...
- Swift 与 JSON 数据 浅析
转载自:http://www.cnblogs.com/theswiftworld/p/4660177.html 我们大家平时在开发 App 的时候,相信接触最多的就是 JSON 数据了.只要你的 Ap ...
- db2数据导出导入
C:\Users\yexuxia>set db2instance=TCASHMAN C:\Users\yexuxia>db2(c) Copyright IBM Corporation 19 ...
- acm课程练习2--1001
题目描述 Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and ...
- 河南多校联合训练 F 不是匹配
描述 有N个人,N个活动, 每个人只会对2个或者3个活动感兴趣, 每个活动也只有两个人或者两个活动对它兴趣,每个人参加一个 感兴趣的活动需要一天 ,且当天该活动被参加时,其他的人不能参加 如果 ...