Mayor's posters POJ 2528

传送门

线段树区间修改加离散化

#include <cstdio>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<int,int>
const ll INF=1e18;
const int N=1e6+10;
int ans[N];
int l[N],r[N];
struct SegmentTree{
int l,r;
ll dat;
}t[N*4];
void build(int p,int l,int r)
{
t[p].l = l;
t[p].r = r;
t[p].dat = 0;
if(t[p].l == t[p].r){t[p].dat = 0;return ;}
int mid = (l+r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
}
void spread(int p)
{
if(t[p].dat)
{
t[p*2].dat = t[p].dat;
t[p*2+1].dat = t[p].dat;
t[p].dat = 0;
}
}
void change(int p,int l,int r,ll v)
{
if(l <= t[p].l && t[p].r <= r)
{
t[p].dat = v;
return ;
}
int mid = (t[p].l+t[p].r)/2;
spread(p);
if(l<=mid) change(p*2,l,r,v);
if(r>mid) change(p*2+1,l,r,v);
}
void ask(int p,int l,int r)
{
if(t[p].dat)
{
ans[t[p].dat] = 1;
return ;
}
if(t[p].l == t[p].r)
return;
int mid = (t[p].l+t[p].r)/2;
spread(p);
ask(p*2,l,r);
ask(p*2+1,l,r);
}
vector<int>num;
int n;
int main()
{
ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--)
{
cin >> n;
num.clear();
for(int i=1;i<=n;i++)
{
cin >> l[i] >> r[i];
num.push_back(l[i]);
num.push_back(r[i]);
}
sort(num.begin(),num.end());
num.erase(unique(num.begin(),num.end()),num.end());
int m = num.size();
for(int i=1;i<m;i++)
{
if(num[i] - num[i-1] > 1)
num.push_back(num[i-1]+1);
}
sort(num.begin(),num.end());
m = num.size();
build(1,0,m-1);
for(int i=1;i<=n;i++)
{
ans[i] = 0;
int x = lower_bound(num.begin(),num.end(),l[i])-num.begin();
int y = lower_bound(num.begin(),num.end(),r[i])-num.begin();
change(1,x,y,i);
}
int res = 0;
ask(1,0,m-1);
for(int i=1;i<=n;i++)
{
if(ans[i])
res++;
}
cout << res << "\n";
}
return 0;
}

poj 2528 线段树区间修改+离散化的更多相关文章

  1. Mayor's posters POJ - 2528 线段树区间覆盖

    //线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...

  2. LightOJ 1089 - Points in Segments (II) 线段树区间修改+离散化

    http://www.lightoj.com/volume_showproblem.php?problem=1089 题意:给出许多区间,查询某个点所在的区间个数 思路:线段树,由于给出的是区间,查询 ...

  3. POJ - 3468 线段树区间修改,区间求和

    由于是区间求和,因此我们在更新某个节点的时候,需要往上更新节点信息,也就有了tree[root].val=tree[L(root)].val+tree[R(root)].val; 但是我们为了把懒标记 ...

  4. POJ 3468 线段树区间修改查询(Java,c++实现)

    POJ 3468 (Java,c++实现) Java import java.io.*; import java.util.*; public class Main { static int n, m ...

  5. A Simple Problem with Integers POJ - 3468 线段树区间修改+区间查询

    //add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #includ ...

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

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  7. Codeforces Round #442 (Div. 2) E Danil and a Part-time Job (dfs序加上一个线段树区间修改查询)

    题意: 给出一个具有N个点的树,现在给出两种操作: 1.get x,表示询问以x作为根的子树中,1的个数. 2.pow x,表示将以x作为根的子树全部翻转(0变1,1变0). 思路:dfs序加上一个线 ...

  8. 题解报告:hdu 1698 Just a Hook(线段树区间修改+lazy懒标记的运用)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

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

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

随机推荐

  1. 非常NB的一款快捷启动软件--Merry

    Merry 被设计为了能将日常重复性操作简化为一个快捷键或者命令.Merry 采用完全开放的体系, 可以使用 Lua 或者外部程序来扩展 Merry 的功能. 另附一个自己扩展的LUA脚本: --启动 ...

  2. linux入门系列9--用户管理及文件权限控制

    ​ 前面文章分享了Linux下常用命令以及Shell编程相关知识,本节继续学习Linux用户管理及文件权限控制. ​ Linux是多用户多任务操作系统,具有很好的稳定性和安全性.既然是多用户,那就意味 ...

  3. 在4K屏下以超过VMWare默认的最高分辨率运行Linux系统

    前言 4K 屏,有其优点也有其弊端.优点就是分辨率高,字体和图标看起来如丝一般顺滑:缺点就是字体和图标小,费眼睛.解决这个缺点的方法也很简单粗暴,就是将系统的显示比例放大.在高分屏不很普及的时候,无论 ...

  4. 《Python学习手册 第五版》 -第4章 介绍Python对象类型

    本章的内容主要是介绍了Python的核心对象类型,后续的5.6.7.8.9章针对这些核心类型分别展开详细的说明 本章我认为重要的有几点 1.作者有谈到Python的知识结构,这个我感觉是一个大框架,可 ...

  5. (七)mybatis批量操作,分页插件

    首先使用方式很简单: SqlSession sqlSession = sessionFactory.openSession(ExecutorType.BATCH); 批量操作核心:改变执行sql的方式 ...

  6. 初入机器学习,安装tensorflow包等问题总结

    学习python,机器学习(maching-lerning).深度学习(deep-learning)等概念也是耳熟能详.我最近从新手开始学习maching-learning知识,不过课程偏向基本的理论 ...

  7. 【Bullet引擎】Bullet物理引擎简单说明

    说明 Bullet是一款开源的物理模拟计算引擎,包括刚体.柔体.弹性体等,是世界三大物理模拟引擎之一(包括Havok和PhysX),被广泛应用于游戏开发(GTA5等)和电影(2012等)制作中. Bu ...

  8. 提升命令行效率的Bash快捷键

    转自:http://linuxtoy.org/archives/bash-shortcuts.html 生活在 Bash shell 中,熟记以下快捷键,将极大的提高你的命令行操作效率. 大部分对其他 ...

  9. CentOS安装-(CentOS7)最小化安装

    镜像:CentOS-7-x86_64-DVD-1908.iso 1.将安装光盘插入服务器,开机会读取系统安装程序,选择 Install CentOS 7 2.安装过程是图形界面,可以选择熟悉的语言执行 ...

  10. VFP 的 CursorAdapter 相关

    VFP 的 CursorAdapter 是在VFP 8 中增加的最重要的新功能,它提供了一种采用统一接口的方式来访问远程数据源. 现在正值新冠肺炎期间,闲着也是闲着,在整理原理的资料时,发现十多年前的 ...