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> ...
随机推荐
- Delphi如何处理不同类型的文件
参考:http://www.cnblogs.com/railgunman/articles/1800318.html 程序设计当中,我们时常遇到需要处理文件.目录及驱动器的情况,这里将对如何处理不同类 ...
- ExcelReport第一篇:使用ExcelReport导出Excel
导航 目 录:基于NPOI的报表引擎——ExcelReport 下一篇:ExcelReport源码解析 概述 本篇将通过导出学生成绩的示例演示“使用ExcelReport导出Excel”的步骤. ...
- 【openGL】关于画点
#include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...
- 《精通Hibernate:Java对象持久化技术详解》目录
图书信息:孙卫琴 电子工业出版社 第1章 Java应用分层架构及软件模型: 1.1 应用程序的分层体系结构 1.1.1 区分物理层和逻辑层 1.1.2 软件层的特征 1.1.3 软件分层的优点 1.1 ...
- ASP.NET多线程下使用HttpContext.Current为null解决方案 2015-01-22 15:23 349人阅读 评论(0) 收藏
问题一:多线程下获取文件绝对路径 当我们使用HttpContext.Current.Server.MapPath(strPath)获取绝对路径时HttpContext.Current为null,解决办 ...
- Uncaught ReferenceError: console is not defined
今天写javascript代码遇到了这个极其神奇的问题,居然报错说内置的console不存在,而且后来我换成了alert也不行.照例说这些都是js代码内置的东西不应该出现这种错误.不过百度之发现貌似没 ...
- 如何在java程序中调用linux命令或者shell脚本
转自:http://blog.sina.com.cn/s/blog_6433391301019bpn.html 在java程序中如何调用linux的命令?如何调用shell脚本呢? 这里不得不提到ja ...
- JMockit
[TOC] 简介 JMockit是基于JavaSE5中的java.lang.instrument包开发,内部使用ASM库来动态修改java的字节码,使得java这种静态语言可以想动态脚本语言一样动态设 ...
- 如果我可以重新学习iOS开发(转)
在过去的几个月里,我一直在学习用Objective-C编写iOS app,最后我开始理清思绪.这比我想象中要难很多,也花了太长时间. 我经常遇到困难.感到沮丧,修复bug比实际写代码要花太多时间.但是 ...
- NuGet学习笔记(1) 初识NuGet及快速安装使用
关于NuGet园子里已经有不少介绍及使用经验,本文仅作为自己研究学习NuGet一个记录. 初次认识NuGet是在去年把项目升级为MVC3的时候,当时看到工具菜单多一项Library Package M ...