Codeforces Beta Round #35 (Div. 2) E. Parade(扫描线)
只要会做,周长并,这题肯定有思路。
有个小地方敲错了,细心啊,扫描线,有一段时间没写过了,还有注意排序的问题,很重要。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL __int64
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int que[];
int sum[*];
int cnt[*];
int ax[],ay[];
struct node
{
int h,x,c;
node(){}
node(int a,int b,int c):h(a),x(b),c(c){}
bool operator < (const node &S)const
{
if(x == S.x)
{
if(c != S.c)
return c > S.c;
else if(c == )
return h > S.h;
else if(c == -)
return h < S.h;
}
return x < S.x;
}
}mat[];
void pushup(int rt,int l,int r)
{
if(cnt[rt])
sum[rt] = que[r+] - que[l];
else if(l == r)
sum[rt] = ;
else
sum[rt] = sum[rt<<] + sum[rt<<|];
}
void update(int L,int R,int c,int l,int r,int rt)
{
int m;
if(L <= l&&r <= R)
{
cnt[rt] += c;
pushup(rt,l,r);
return ;
}
m = (l + r)>>;
if(L <= m)
update(L,R,c,lson);
if(R > m)
update(L,R,c,rson);
pushup(rt,l,r);
return ;
}
int bin(int x,int y)
{
int str,end,mid;
str = ;
end = y;
while(str <= end)
{
mid = (str+end)/;
if(que[mid] == x)
return mid;
else if(que[mid] > x)
end = mid - ;
else
str = mid + ;
}
return mid;
}
int main()
{
int n,i,h,l,r,num;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d",&n);
num = ;
for(i = ;i < n;i ++)
{
scanf("%d%d%d",&h,&l,&r);
que[i] = h;
mat[num++] = node(h,l,);
mat[num++] = node(h,r,-);
}
que[n] = ;
sort(que,que+n+);
sort(mat,mat+num);
int k = ;
for(i = ;i <= n;i ++)
{
if(que[i] != que[i-])
que[k++] = que[i];
}
int tn = ,pre = ;
for(i = ;i < num;i ++)
{
l = ;
r = bin(mat[i].h,k-) - ;
if(l <= r)
{
update(l,r,mat[i].c,,k-,);
}
if(pre != sum[])
{
ax[tn] = mat[i].x;
ay[tn++] = pre;
ax[tn] = mat[i].x;
ay[tn++] = sum[];
pre = sum[];
}
}
printf("%d\n",tn);
for(i = ;i < tn;i ++)
{
printf("%d %d\n",ax[i],ay[i]);
}
return ;
}
Codeforces Beta Round #35 (Div. 2) E. Parade(扫描线)的更多相关文章
- Codeforces Beta Round #35 (Div. 2)
Codeforces Beta Round #35 (Div. 2) http://codeforces.com/contest/35 A 这场的输入输出是到文件中的,不是标准的输入输出...没注意看 ...
- Codeforces Beta Round #18 (Div. 2 Only)
Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc+ ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- 重温WCF之会话Session(九)
转载地址:http://blog.csdn.net/tcjiaan/article/details/8281782 每个客户端在服务器上都有其的独立数据存储区,互不相干,就好像A和服务器在单独谈话一样 ...
- Myeclipse 2016 & 2014 下载
myeclipse-2016-ci-6-offline-installer-windowshttps://downloads.genuitec.com/downloads/myeclipse/inst ...
- Pyqt QListWidget之缩略图列表
QListWidget 可以设置模型setViewMode 当setViewMode值为QListView.IconMode 表示Icon模式 以下代码来自Pyqt Example #!/usr/b ...
- BAT批量处理 命令
第一章 批处理基础第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT或者CMD.这些命令统称批处理命令.小知识:可以 ...
- php获取当前毫秒时间戳
最近在做一个智能家居项目的后台,需要实时上传用户对智能设备的配置信息到服务器,以便实现同步,因此对于时间的精确度要求比较高,最开始直接是用php的time()函数来获取时间戳,获取的时间精确到秒级别, ...
- android开源项目和框架(转)
特效: http://www.androidviews.net/ http://www.theultimateandroidlibrary.com/ 常用效果: 1. https://github.c ...
- 在Salesforce中以PDF的格式显示对应的页面
在Salesforce中可以简单设置page的属性让页面以pdf的方式显示内容, 当然了我们的page内容可以用Html的方式编写 设置方式为:renderAs="pdf" 请看如 ...
- loj1011 状态压缩
题目链接:http://lightoj.com/volume_showproblem.php?problem=1011 思路:最近的开始做dp了...很明显的一道状态压缩题,dp[n][state]表 ...
- loj 1037(状压dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25914 思路:dp[state]表示当前状态下要消耗的最小的sho ...
- 分享Kali Linux 2016.2第46周虚拟机
分享Kali Linux 2016.2第46周虚拟机该虚拟机使用Kali Linux 2016.2第46周的64位镜像安装.桌面为Gnome模式.该虚拟机配置如下:(1)支持VMWare 9以上的版本 ...