水博客,水一水。

Horizontally Visible Segments
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 6290   Accepted: 2287

Description

There is a number of disjoint vertical line segments in the plane. We say that two segments are horizontally visible if they can be connected by a horizontal line segment that does not have any common points with other vertical segments. Three different vertical segments are said to form a triangle of segments if each two of them are horizontally visible. How many triangles can be found in a given set of vertical segments?

Task

Write a program which for each data set:

reads the description of a set of vertical segments,

computes the number of triangles in this set,

writes the result.

Input

The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 20. The data sets follow.

The first line of each data set contains exactly one integer n, 1 <= n <= 8 000, equal to the number of vertical line segments.

Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:

yi', yi'', xi - y-coordinate of the beginning of a segment, y-coordinate of its end and its x-coordinate, respectively. The coordinates satisfy 0 <= yi' < yi'' <= 8 000, 0 <= xi <= 8 000. The segments are disjoint.

Output

The output should consist of exactly d lines, one line for each data set. Line i should contain exactly one integer equal to the number of triangles in the i-th data set.

Sample Input

1
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3

Sample Output

1

题意:输入n表示有n条线段,n行每行输入y1,y2,x表示线段的下端点,上端点以及线段的位置(横坐标位置),对于第i条线段和第k条线段如果用一条平行线能够经过它们并且在它们之间不经过其他线段,则称这两条线段互为可见,求有多少3条线段两两可见(懒得写题意,直接贴的别人的)

代码:

 //线段树区间更新,端点放大2倍
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef long long ll;
const int maxn=8e3+; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 int col[maxn<<];
bool mp[maxn][maxn]; struct node{
int y1,y2,x,id;
}line[maxn]; bool cmp(node a,node b)
{
return a.x<b.x;
} void init()
{
memset(mp,,sizeof mp);
memset(line,,sizeof line);
memset(col,,sizeof col);
} void pushdown(int rt)
{
if(col[rt]){
col[rt<<]=col[rt<<|]=col[rt];
col[rt]=;
}
} void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R){
col[rt]=c;
return ;
} pushdown(rt);
int m=(l+r)>>;
if(L<=m) update(L,R,c,lson);
if(R> m) update(L,R,c,rson);
} void query(int L,int R,int c,int l,int r,int rt)
{
if(col[rt]){
mp[c][col[rt]]=;
return ;
} if(l==r){
return ;
} int m=(l+r)>>;
if(L<=m) query(L,R,c,lson);
if(R> m) query(L,R,c,rson);
} int main()
{
int t;
scanf("%d",&t);
while(t--){
init();
int n;
scanf("%d",&n);
int N=-;
for(int i=;i<=n;i++){
scanf("%d%d%d",&line[i].y1,&line[i].y2,&line[i].x);
line[i].id=i;line[i].y1*=;line[i].y2*=;N=max(N,max(line[i].y1,line[i].y2));
}
sort(line+,line++n,cmp);//按x轴从小到大排序,降维,只对y轴进行建树
for(int i=;i<=n;i++){
query(line[i].y1,line[i].y2,line[i].id,,N,);
update(line[i].y1,line[i].y2,line[i].id,,N,);
}
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(mp[i][j]){
for(int k=;k<=n;k++){
if(mp[i][k]&&mp[k][j]) ans++;
}
}
}
}
printf("%d\n",ans);
}
}

POJ 1436.Horizontally Visible Segments-线段树(区间更新、端点放大2倍)的更多相关文章

  1. (中等) POJ 1436 Horizontally Visible Segments , 线段树+区间更新。

    Description There is a number of disjoint vertical line segments in the plane. We say that two segme ...

  2. POJ 1436 Horizontally Visible Segments (线段树&#183;区间染色)

    题意   在坐标系中有n条平行于y轴的线段  当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交  就视为它们是可见的  问有多少组三条线段两两相互可见 先把全部线段存下来  并按x ...

  3. POJ 1436 Horizontally Visible Segments(线段树)

    POJ 1436 Horizontally Visible Segments 题目链接 线段树处理染色问题,把线段排序.从左往右扫描处理出每一个线段能看到的右边的线段,然后利用bitset维护枚举两个 ...

  4. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  5. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  6. POJ 1436 Horizontally Visible Segments

    题意: 有一些平行于y轴的线段 ,两条线段称为互相可见当且仅当存在一条水平线段连接这两条  与其他线段没交点. 最后问有多少组  3条线段,他们两两是可见的. 思路: 线段树,找出两两可见的那些组合, ...

  7. poj 2528 Mayor's posters 线段树区间更新

    Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...

  8. poj 2777 Count Color(线段树 区间更新)

    题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释,  参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...

  9. POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】

    任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total S ...

随机推荐

  1. win add static arp

    win add static arp > arp -s "192.168.0.2" "00-0a-35-01-fe-c0" > arp -a | f ...

  2. 详细介绍:Kubernetes1.4版本的新功能

    Kubernetes1.4主要新特性 创建kubernetes集群只需要两条命令 增强了对有状态应用的支持 增加了集群联盟API 支持容器安全控制 增强包括调度在内的Kubernetes基础架构 通过 ...

  3. 英文FRAUNCE法国FRAUNCE单词

    France Alternative forms Fraunce In Fraunce, the inhabitants of one city were driven out and forced ...

  4. 推荐一个去除图片人物背景的工具Removebg

    可以在线使用,url:https://www.remove.bg/users/sign_in 用邮箱免注册一个免费账号: 注册的邮箱会收到一封激活账号的邮件: 点击Activate account后激 ...

  5. Solr基础知识二(导入数据)

    上一篇讲述了solr的安装启动过程,这一篇讲述如何导入数据到solr里. 一.准备数据 1.1 学生相关表 创建学生表.学生专业关联表.专业表.学生行业关联表.行业表.基础信息表,并创建一条小白的信息 ...

  6. 给 linux redis 设置密码

    在redis.conf 找到 下面添加一行: 这样的话,密码就可以设置成123456,然后重启redis就可以了.

  7. 图记 2016.1.7 获取本地图片、Bitmap转image

    这几天完成的内容有: 1.“添加图片”按钮 2.添加图片功能 遇到的问题: 我想要将添加图片按钮放在右下角,所以采用了相对布局,但是问题随之二来,因为将导航栏设置成了半透明,所以图片放到右下角之后,半 ...

  8. 《深入理解 Java 虚拟机》读书笔记:Java 内存区域与内存溢出异常

    前言 最近开始看这本书,记得前段时间拿起这本书的时候,心情是相当沉重的!当时的剧本是这样的-- 内景.家里 - 下午 我(画外):唉,有点无聊啊!(偶然撇过书架)这么多书得看到什么时候啊,要不要拿一本 ...

  9. MySQL/MariaDB数据库的mysqldump工具备份还原实战

    MySQL/MariaDB数据库的mysqldump工具备份还原实战 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.mysqldump概述 1>.逻辑备份工具 mysq ...

  10. php中函数的类型提示和文件读取功能

    这个没有深入. <?php function addNumbers(int $a, int $b, bool $printSum): int { $sum = $a + $b; if ($pri ...