poj2528 Mayor's posters(线段树区间修改+特殊离散化)
Description
- Every candidate can place exactly one poster on the wall.
- All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
- The wall is divided into segments and the width of each segment is one byte.
- Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
Input
Output
The picture below illustrates the case of the sample input.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int M = 2e5 + 10;
int a[M] , b[M] , c[2 * M] , d[2 * M] , e[4 * M];
struct TnT {
int l , r , num , add;
}T[M << 2];
int re;
void push(int p) {
if(T[p].add) {
T[p << 1].num = (T[p << 1].r - T[p << 1].l + 1);
T[(p << 1) | 1].num = (T[(p << 1) | 1].r - T[(p << 1) | 1].l + 1);
T[p << 1].add = T[p].add;
T[(p << 1) | 1].add = T[p].add;
T[p].add = 0;
}
}
void build(int l , int r , int p) {
int mid = (l + r) >> 1;
T[p].l = l , T[p].r = r , T[p].num = 0 , T[p].add = 0;
if(T[p].l == T[p].r) {
return ;
}
build(l , mid , p << 1);
build(mid + 1 , r , (p << 1) | 1);
T[p].num = T[p << 1].num + T[(p << 1) | 1].num;
}
void updata(int l , int r , int p) {
int mid = (T[p].l + T[p].r) >> 1;
if(T[p].l == l && T[p].r == r) {
T[p].add = 1;
T[p].num = (r - l + 1);
return ;
}
push(p);
if(mid < l) {
updata(l , r , (p << 1) | 1);
}
else if(mid >= r) {
updata(l , r , p << 1);
}
else {
updata(l , mid , p << 1);
updata(mid + 1 , r , (p << 1) | 1);
}
T[p].num = T[p << 1].num + T[(p << 1) | 1].num;
}
int query(int l , int r , int p) {
int mid = (T[p].l + T[p].r) >> 1;
if(T[p].l == l && T[p].r == r) {
return T[p].num;
}
push(p);
T[p].num = T[p << 1].num + T[(p << 1) | 1].num;
if(mid < l) {
return query(l , r , (p << 1) | 1);
}
else if(mid >= r) {
return query(l , r , p << 1);
}
else {
return query(l , mid , p << 1) + query(mid + 1 , r , (p << 1) | 1);
}
}
int search(int ll, int hh, int xx) {
int mm;
while (ll <= hh) {
mm = (ll + hh) >> 1;
if (e[mm] == xx) return mm;
else if (e[mm] > xx) hh = mm - 1;
else ll = mm + 1;
}
return -1;
}
int main()
{
int t;
scanf("%d" , &t);
while(t--) {
int n;
scanf("%d" , &n);
int gg = 0;
for(int i = 1 ; i <= n ; i++) {
scanf("%d%d" , &a[i] , &b[i]);
c[++gg] = a[i];
c[++gg] = b[i];
}
sort(c + 1 , c + gg + 1);
int mm = 0;
c[gg + 1] = -1;
for(int i = 1 ; i <= gg ; i++) {
if(c[i] != c[i + 1]) {
d[++mm] = c[i];
}
}
e[1] = d[1];
int mt = 1;
for(int i = 2 ; i <= mm ; i++) {
if(d[i] - d[i - 1] > 1) {
e[++mt] = d[i - 1] + 1;
e[++mt] = d[i];
}
else {
e[++mt] = d[i];
}
}
// for(int i = 1 ; i <= mt ; i++) {
// cout << e[i] << ' ';
// }
build(1 , mt + 1 , 1);
int count = 0;
for(int i = n ; i >= 1 ; i--) {
int r = search(1 , mt , b[i]);
int l = search(1 , mt , a[i]);
re = query(l , r , 1);
//cout << re << endl;
if(re < r - l + 1) {
count++;
}
updata(l , r , 1);
}
printf("%d\n" , count);
}
return 0;
}
poj2528 Mayor's posters(线段树区间修改+特殊离散化)的更多相关文章
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- poj2528 Mayor's posters(线段树区间覆盖)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 50888 Accepted: 14737 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ2528 Mayor's posters —— 线段树染色 + 离散化
题目链接:https://vjudge.net/problem/POJ-2528 The citizens of Bytetown, AB, could not stand that the cand ...
- [poj2528] Mayor's posters (线段树+离散化)
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- poj2528 Mayor's posters(线段树之成段更新)
Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Descr ...
随机推荐
- WTM 构建DotNetCore开源生态,坐而论道不如起而行之
作为一个8岁开始学习编程,至今40岁的老程序员,这辈子使用过无数种语言,从basic开始,到pascal, C, C++,到后来的 java, c#,perl,php,再到现在流行的python. 小 ...
- .Net集合详解
前言 前面几篇文章讲了泛型.讲了数组,都有提到集合,这一节重点对集合进行详细解说.本文主要使用各种集合类型.以至于评估其性能,针对不同的场景选择不同的集合使用. 集合分类详解 一.列表 列表的创建 v ...
- linux字符设备驱动中内核如何调用驱动入口函数 一点记录
/* 内核如何调用驱动入口函数 ? *//* 答: 使用module_init()函数,module_init()函数定义一个结构体,这个结构体里面有一个函数指针,指向first_drv_init() ...
- 标签助手(TagHelper)
1.什么是标签助手 Tag Helper 标签助手是服务端代码能够参与在 Razor 文件中创建和呈现HTML元素.例如,内置的 ImageTagHelper 可以将版本号追加到图像名称.无论何时更改 ...
- 3、数组的声明及初始化(test1.java)
今天学习了,一位数组和二维数组,先学习了数组的申请,数组的初始化,数组的拷贝等.对于数组我认为,和C\C++中的数组,没有什么太大的区别,但是在JAVA中,大家都知道JAVA是面向对象的编程语言,每一 ...
- ZDog:简单便捷好玩的的3D设计和动画制作库
各位老铁,我灰太狼又又又回来了,嘿嘿!!!!最近在忙所以有日子没写博客了,今天带大家看个好玩的东西 这个东西是今天偶尔看到的,是啥呢,难道是漂亮的小姐姐吗?当然是......不可能的了,这个东西其实就 ...
- LeetCode——409. Longest Palindrome
题目: Given a string which consists of lowercase or uppercase letters, find the length of the longest ...
- flask项目部署到云服务器+域名绑定
一.效果演示 首页展示 播放页面 该项目部署只为学习,所以用的服务器是腾讯云服务器10元/月,域名也是在腾讯云买的.com 55元/年 因为本人比较穷 哈哈
- BFS-迷宫问题
问题描述 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...
- 解决MobaXterm-SSH中文乱码问题
一般情况不用修改服务器字符集(linux或unix服务器字符集一般不会设置错误). 1.首先用命令查看当前系统的LANG是什么: >locale LANG=en_US LC_COLLATE=&q ...