poj2528 Mayor's posters (线段树+离散化)
恩,这区间范围挺大的,需要离散化。如果TLE,还需要优化一下常数。
AC代码
#include <stdio.h>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
const int maxn = +;
typedef pair<int, int> Pii;
Pii a[ + ];
int b[maxn], vis[+], c[maxn]; int setv[maxn << ]; void buildTree(int o, int l, int r) {
setv[o] = -;
if(l < r) {
int m = (l+r) / ;
buildTree(o*, l, m);
buildTree(o*+, m+, r);
}
} void pushDown(int o) {
int lc = o*, rc = o*+;
if(setv[o] != -) {
setv[lc] = setv[rc] = setv[o];
}
setv[o] = -;
} int ul, ur;
void update(int o, int l, int r, int v) {
if(ul <= l && r <= ur) {
setv[o] = v;
} else {
pushDown(o);
int m = (l+r) / ;
if(ul <= m)
update(o*, l, m, v);
if(m < ur)
update(o*+, m+, r, v);
}
} void query(int o) {
if(setv[o] != -) {
vis[setv[o]] = ;
return;
}
query(o*);
query(o*+);
} int main() {
int T, n;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d%d", &a[i].first, &a[i].second);
b[i*] = a[i].first;
b[i*+] = a[i].second;
}
sort(b, b+*n);
int cnt = ;
c[] = b[];
cnt = ;
for(int i = ; i < *n; i++) {
if(b[i] == b[i-]) continue;
if(b[i] - b[i-] > )
c[cnt++] = b[i-] + ;
c[cnt++] = b[i];
}
buildTree(, , cnt);
for(int i = ; i < n; i++) {
ul = lower_bound(c, c+cnt, a[i].first) - c + ;
ur = lower_bound(c, c+cnt, a[i].second) - c + ;
update(, , cnt, i);
}
memset(vis, , sizeof(vis));
query();
int ans = ;
for(int i = ; i < n; i++) {
ans += vis[i];
}
printf("%d\n", ans);
}
return ;
}
poj2528 Mayor's posters (线段树+离散化)的更多相关文章
- [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: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ... 
- POJ 2528 Mayor's posters(线段树+离散化)
		Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ... 
- poj 2528 Mayor's posters 线段树+离散化技巧
		poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ... 
- Mayor's posters (线段树+离散化)
		Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ... 
- Mayor's posters(线段树+离散化POJ2528)
		Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ... 
- 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 mayoral electio ... 
- 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:75394 Accepted: 21747 ... 
随机推荐
- 【actitivi】配置运行上遇到的问题
			基础: 需要 问题1:对于activiti-admin,添加mysql-connector-java-5.1.47.jar后: Sun Apr 28 16:09:00 CST 2019 WARN: E ... 
- Linux的发展历史
			创始人: linux操作系统由林纳斯·本纳第克特·托瓦兹编写而成,是管理电脑硬件以及运行电脑软件的操作系统. 创始发展过程:Linux操作系统的诞生.发展和成长过程始终依赖着五个重要支柱:UNIX 操 ... 
- Cocos Creator  按钮音效封装重写
			cc.Button.prototype._onTouchEnded = function (t) { cc.hb.audioMgr.playMusic("click", false ... 
- Nginx配置选项
			--prefix=path 定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录.默认使用 /usr/local/nginx. --sbin-path=path 设置nginx的可执行 ... 
- 纯JS.CSS编写的可拖拽并左右分栏的插件(复制代码就能用)
			<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equ ... 
- C# 合并只要有交集的所有集合
			using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ... 
- 微信中H5网页如何唤醒打开外部浏览器打开指定链接
			最近遇到一个需求.朋友找我制作一个在微信中的聊天框,或者公众号菜单发布一条链接或者二维码.跳出微信打开一个指定的我们自己的页面, 拿到这个需求后我们团队分开去找资料研究方案,通过微信的开发文档.腾讯的 ... 
- 已有的PHP安装gd扩展
			第一步 安装依赖 1.安装xpm yum install libXpm-devel 2.安装zlib wget http://zlib.net/zlib-1.2.8.tar.gz tar -xzvf ... 
- selenium 定位密码软键盘
			from selenium import webdriver import time driver = webdriver.Chrome() driver.maximize_window() driv ... 
- SQL Server实现远程访问
			1.打开SQL Server 配置管理器(SQL Server Configuration Manager) 2.启用SQL Server网络配置的TCP/IP:选中左侧的「SQL Server网络配 ... 
