由于上下线段是不可能有交点的

可以先看左右线段树,按照y递增的顺序,对点进行排序。

升序构造,那么对于从某一点往下的射线,对于L,R进行区间覆盖,线段交点个数就是单点的被覆盖的次数。

降序构造,那么对于从某个点从下往上的射线,所有y坐标比期大的点都进行了区间覆盖,那么单点就是答案。

最近脑子不太好。。。思路一定要清晰啊。。。

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<vector>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define LL long long
#define lson rt<<1
#define rson rt<<1|1
using namespace std;
const int maxx = 2e5+;
struct node{
int l,r,laze;
int w;
}tree[maxx<<];
vector<int>vx;
vector<int>vy;
struct Point{
int x,y;
char op;
}p[maxx];
int getx(int x){
return lower_bound(vx.begin(),vx.end(),x)-vx.begin()+;
}
int gety(int x){
return lower_bound(vy.begin(),vy.end(),x)-vy.begin()+;
}
void push_donw(int rt){
if (tree[rt].laze){
tree[lson].laze+=tree[rt].laze;
tree[rson].laze+=tree[rt].laze;
tree[lson].w+=tree[rt].laze*(tree[lson].r-tree[lson].l+);
tree[rson].w+=tree[rt].laze*(tree[rson].r-tree[rson].l+);
tree[rt].laze=;
}
}
void buildtree(int rt,int l,int r){
tree[rt].l=l;
tree[rt].r=r;
tree[rt].laze=;
tree[rt].w=;
if (l==r){
return ;
}
int mid=(l+r)>>;
buildtree(lson,l,mid);
buildtree(rson,mid+,r);
}
void update(int rt,int ql,int qr,int w){
int l=tree[rt].l;
int r=tree[rt].r;
if (ql<=l && r<=qr){
tree[rt].laze+=w;
tree[rt].w+=w*(r-l+);
return;
}
int mid=(l+r)>>;
push_donw(rt);
if (qr<=mid){
update(lson,ql,qr,w);
}else if(ql>mid){
update(rson,ql,qr,w);
}else {
update(lson,ql,mid,w);
update(rson,mid+,qr,w);
}
tree[rt].w=tree[lson].w+tree[rson].w;
}
int query(int rt,int pos){
int l=tree[rt].l;
int r=tree[rt].r;
if (l==r){
return tree[rt].w;
}
int mid=(l+r)>>;
push_donw(rt);
if (pos<=mid){
return query(lson,pos);
}else {
return query(rson,pos);
}
tree[rt].w=tree[lson].w+tree[rson].w;
}
bool cmp(Point a,Point b){
return a.y<b.y;
}
int main(){
int t;
int n,m,k;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
vx.clear();
vy.clear();
for (int i=;i<=k;i++){
scanf("%d%d %c",&p[i].x,&p[i].y,&p[i].op);
vx.push_back(p[i].x);
vy.push_back(p[i].y);
}
sort(vx.begin(),vx.end());
sort(vy.begin(),vy.end());
vx.erase(unique(vx.begin(),vx.end()),vx.end());
vy.erase(unique(vy.begin(),vy.end()),vy.end());
sort(p+,p++k,cmp);
int sz=vx.size();
buildtree(,,sz);
LL ans=;
for (int i=;i<=k;i++){
if (p[i].op=='D'){
ans+=query(,getx(p[i].x));
}else if (p[i].op=='L'){
update(,,getx(p[i].x),);
}else if (p[i].op=='R'){
update(,getx(p[i].x),sz,);
}
}
buildtree(,,sz);
for (int i=sz;i>=;i--){
if (p[i].op=='U'){
ans+=query(,getx(p[i].x));
}else if (p[i].op=='L'){
update(,,getx(p[i].x),);
}else if (p[i].op=='R'){
update(,getx(p[i].x),sz,);
}
}
printf("%d\n",ans+);
}
return ;
}

Rikka with Mista 线段树求交点个数的更多相关文章

  1. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  2. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  3. BNU 2418 Ultra-QuickSort (线段树求逆序对)

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=2418 解题报告:就是给你n个数,然后让你求这个数列的逆序对是多少?题目中n的范围是n & ...

  4. HDU5634 Rikka with Phi 线段树

    // HDU5634 Rikka with Phi 线段树 // 思路:操作1的时候,判断一下当前区间是不是每个数都相等,在每个数相等的区间上操作.相当于lazy,不必更新到底. #include & ...

  5. hdu 1394 (线段树求逆序数)

    <题目链接> 题意描述: 给你一个有0--n-1数字组成的序列,然后进行这样的操作,每次将最前面一个元素放到最后面去会得到一个序列,那么这样就形成了n个序列,那么每个序列都有一个逆序数,找 ...

  6. <Sicily>Inversion Number(线段树求逆序数)

    一.题目描述 There is a permutation P with n integers from 1 to n. You have to calculate its inversion num ...

  7. HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)

    HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意:  给一个序列由 ...

  8. hdu 1754 I Hate It (线段树求区间最值)

    HDU1754 I Hate It Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  9. UVA 11983 Weird Advertisement --线段树求矩形问题

    题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...

随机推荐

  1. 基于pytest的接口测试

    最近要开展接口测试,起初打算使用公司已有的Fitnesse测试工具来进行接口测试.过程中发现,构造接口字段数据.测试数据都比较困难,接口参数多的时候,用例量就会很多,关键执行速度还慢.所以放弃了. 找 ...

  2. 七.RBM受限玻尔兹曼机

    1.受限玻尔兹曼机   玻尔兹曼机是一大类的神经网络模型,但是在实际应用中使用最多的则是受限玻尔兹曼机(RBM). 受限玻尔兹曼机(RBM)是一个随机神经网络(即当网络的神经元节点被激活时会有随机行为 ...

  3. 图文结合深入理解 JS 中的 this 值

    图文结合深入理解 JS 中的 this 值 在 JS 中最常见的莫过于函数了,在函数(方法)中 this 的出现频率特别高,那么 this 到底是什么呢,今天就和大家一起学习总结一下 JS 中的 th ...

  4. python通过http(multipart/form-data)上传文件的方法

    之前写过一篇博客,说的如何python如何通过http下载文件,今天写一篇博客来介绍如下,python如何通过request库实现上传文件 这里主要是解决multipart/form-data这种格式 ...

  5. CEF 框架使用集锦

    CEF 框架使用集锦: 参考:〓https://github.com/NetDimension/NanUI/wiki/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8NanUI ...

  6. element-ui表格列金额显示两位小数

    对于金额的显示,大多情况下需要保留两位小数,比如下面的(表格采用 element-ui): 在vue.js中,对文本的处理通常是通过设置一系列的过滤器,过滤器可以用在两个地方:双花括号插值 和 v-b ...

  7. phpcms推送文章同时推送自定义字段

    首先进入phpcms后台,模型管理-字段管理里,新建字段,新建字段必须是主表字段,如图所示 2 来到网站根目录,寻找phpcms\modules\content\classes\push_api.cl ...

  8. TP5动态路由配置好了但是报错was not found on this server的原因以及解决方法

    问题:The requested URL /xxxx.html was not found on this server 原因:apache的重写未开启,开启重写后,问题解决, 方法如下: apach ...

  9. LintCode_67 二叉树中序遍历

    题目 给出一棵二叉树,返回其中序遍历 C++ 非递归 vector<int> inorderTraversal(TreeNode *root) { // write your code h ...

  10. Directx11教程(12) 禁止alt+enter全屏窗口

    原文:Directx11教程(12) 禁止alt+enter全屏窗口        在D3D11应用程序中,我们按下alt+enter键,会切换到全屏模式.有时候,我们在WM_SIZE中有一些代码,全 ...