题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过。

题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同海报的数目,所以可以先对区间进行离散化再进行区间覆盖的操作。

由于墙上不贴东西的时候对后面没有影响, 所以可以不建树, 直接memset一下就好了。

因为是区域覆盖的问题, 树上原来的点并不会对后面的结果产生影响, 所以可以只修改lazy标记而不对树进行修改。

最后再用建树的操作访问一下lazy标记 并记录答案就好了。

代码


 #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
const int N = +;
int tree[N<<], lazy[N<<];
int a[N];
bool vis[N];
int ans, n, t;
pair<int,int> P[N]; void Pushdown(int rt)
{
if(lazy[rt])
{
lazy[rt<<|] = lazy[rt<<] = lazy[rt];
lazy[rt] = ;
}
}
void Revise(int L, int R, int C ,int l, int r, int rt)
{
if(L <= l && r <= R)
{
lazy[rt] = C;
return ;
}
Pushdown(rt);
int m = l+r >> ;
if(L <= m) Revise(L,R,C,lson);
if(m < R) Revise(L,R,C,rson);
}
void build(int l, int r, int rt)
{
if(lazy[rt])
{
if(!vis[lazy[rt]])
{
vis[lazy[rt]] = ;
ans++;
}
return ;
}
int m = l+r >> ;
build(lson);
build(rson);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> t;
while(t--)
{
ans = ;
cin >> n;
for(int i = ; i <= *n; i++)
{
cin >> a[i];
P[i].fi = a[i], P[i].se = i;
}
sort(P+,P+*n+);
int last = , cnt = ;
for(int i = ; i <= *n; i++) //离散化操作
{
if(P[i].fi == last)
a[P[i].se] = cnt;
else a[P[i].se] = ++cnt, last = P[i].fi;
}
memset(lazy, , sizeof(lazy));
for(int i = ; i <= *n; i+=)
Revise(a[i],a[i+],(i+)/,,cnt,);//由于每次的海报不同所以直接给海报一个编号
memset(vis, , sizeof(vis));
build(,cnt,);
cout << ans << endl;
}
return ;
}

POJ 2528 Mayor's posters (线段树+区间覆盖+离散化)的更多相关文章

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

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

  2. POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45703   Accepted: 13239 ...

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

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

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

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

  5. POJ 2528 Mayor’s posters (线段树段替换 && 离散化)

    题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...

  6. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  7. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  8. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  9. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

随机推荐

  1. 用python绘制漂亮的图形

    先看效果,没有用任何绘图工具,只是运行了一段python代码. 代码如下: _ = ( 255, lambda V ,B,c :c and Y(V*V+B,B, c -1)if(abs(V)<6 ...

  2. Task CancellationTokenSource和Task.WhenAll的应用

    Task是.net4.0推出的异步编程类,与ThreadPool.QueneUserWorkItem方法类似的是,Task也是使用线程池来工作的.但Task比起这个QueneUserWorkItem的 ...

  3. Educational Codeforces Round 70 (Rated for Div. 2)

    这次真的好难...... 我这个绿名蒟蒻真的要崩溃了555... 我第二题就不会写...... 暴力搜索MLE得飞起. 好像用到最短路?然而我并没有学过,看来这个知识点又要学. 后面的题目赛中都没看, ...

  4. Go中的函数和闭包

    函数参数和返回值的写法 如果有多个参数是同一个类型,可以简略写: func testReturnFunc(v1,v2 int)(int,int) { x1 := 2 * v1 x2 := 3 * v2 ...

  5. javaScript基础-03 javascript语句

    一. 声明语句 var和function都是声明语句.声明或定义变量或函数. var 声明一个或者多个变量.语法如下: var a ; var b = 1; var c, d; var e = 3; ...

  6. cs231n---CNN架构

    1 LeNet-5 (1998) 第一个被提出的卷积网络架构,深度较浅,用于手写数字识别. 2 AlexNet (2012) 架构为: CONV1 ->MAX POOL1 ->NORM1 ...

  7. python面向对象初始进阶版 通过一道题带你认识面向对象

    定义一个类 class Person: #公共属性 animal='高级动物' soul='有灵魂' language='语言' def init(self,country,name,sex,age, ...

  8. Python自动化开发

    阅读目录 第一篇:python入门 第二篇:字符编码.文件处理 第三篇:函数 第四篇:迭代器.生成器.三元表达式.列表生成式 第五篇:模块.包.软件开发规范 第六篇:日志模块 第七篇:常用模块 第八篇 ...

  9. DC6-靶机渗透

    靶场下载链接: Download: http://www.five86.com/downloads/DC-6.zip Download (Mirror): https://download.vulnh ...

  10. BUPTOJj83

    83. A + B Problem 时间限制 1000 ms 内存限制 65536 KB 题目描述 Calculate the sum of two given integers A and B. 输 ...