题目链接

只要会做,周长并,这题肯定有思路。

有个小地方敲错了,细心啊,扫描线,有一段时间没写过了,还有注意排序的问题,很重要。

 #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(扫描线)的更多相关文章

  1. Codeforces Beta Round #35 (Div. 2)

    Codeforces Beta Round #35 (Div. 2) http://codeforces.com/contest/35 A 这场的输入输出是到文件中的,不是标准的输入输出...没注意看 ...

  2. Codeforces Beta Round #18 (Div. 2 Only)

    Codeforces Beta Round #18 (Div. 2 Only) http://codeforces.com/contest/18 A 暴力 #include<bits/stdc+ ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. ckplayer视频播放插件使用

    研究ckplayer插件播放视频,播放视频需要配置信息修改如下: 1.设置ckplayer.js中的logo: 'null' 可以隐藏视频播放头部的图标: 2.设置ckplayer.js中的ckcpt ...

  2. JS手机浏览器判断(转)

    整理查询一下,js判断手机浏览器的方法 <script type="text/javascript"> /* * 智能机浏览器版本信息:包括微信内置 * */ var ...

  3. cordova

    cordova 1.安装 nodejs => node -v2.安装 npm install -g cordova => cordova -v3.安装 jdk 环境变量:(系统变量) 新建 ...

  4. Linux命令之ar - 创建静态库.a文件和动态库.so

    转自:http://blog.csdn.net/eastonwoo/article/details/8241693 用途说明 创建静态库.a文件.用C/C++开发程序时经常用到,但我很少单独在命令行中 ...

  5. Computer Graphics Research Software

    Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...

  6. BZOJ 1588: [HNOI2002]营业额统计 双向链表 / splay / treap

    1588: [HNOI2002]营业额统计 Description 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger ...

  7. Servlet获取类路径下的资源

    示例程序: package cn.yzu; import java.io.IOException; import java.io.InputStream; import javax.servlet.S ...

  8. Android开发中Handler的经典总结

    当应用程序启动时,Android首先会开启一个主线程(也就是UI线程),主线程为管理界面中的UI控件,进行事件分发. AD: 一.Handler的定义: 主要接受子线程发送的数据, 并用此数据配合主线 ...

  9. HDU 3068 回文串-Manacher

    题意链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 题意:中文题. 思路:Manacher模板题 #include<iostream> ...

  10. Swift3.0语言教程使用Unicode范式标准化获取字符串

    Swift3.0语言教程使用Unicode范式标准化获取字符串 Swift3.0语言教程使用Unicode范式标准化获取字符串,在NSString中可以使用4个属性去使用Unicode范式标准化获取字 ...