恩,这区间范围挺大的,需要离散化。如果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 (线段树+离散化)的更多相关文章

  1. [poj2528] Mayor's posters (线段树+离散化)

    线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayor ...

  2. poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)

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

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

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

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

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

  5. Mayor's posters (线段树+离散化)

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

  6. Mayor's posters(线段树+离散化POJ2528)

    Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...

  7. POJ2528 Mayor's posters —— 线段树染色 + 离散化

    题目链接:https://vjudge.net/problem/POJ-2528 The citizens of Bytetown, AB, could not stand that the cand ...

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

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

  9. poj2528 Mayor's posters(线段树区间修改+特殊离散化)

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

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

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

随机推荐

  1. Windows 系统快速查看文件MD5

    关键 ·打开命令窗口(Win+R),然后输入cmd ·输入命令certutil -hashfile 文件绝对路径 MD5 快速获取文件绝对路径 ·找到文件,右键属性 注意 ·在Win7上,MD5不要使 ...

  2. 请求http页面的相关过程

    http请求从TCP建立三次握手后进行,客户端按照规定的格式向服务器发送http请求,服务器在接收到这个请求之后,首先要对其进行解析,发掘出客户端所需要的相关资源,然后经过相应的业务逻辑处理,找到这个 ...

  3. windows ip路由

    windows 20082块网卡,连接远程mysql数据库一直不通,ping正常,telnet 3306端口不正常 route print 路由情况 route add 10.255.2574.XXX ...

  4. html5 css练习 画廊 元素旋转

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  5. IP通信基础学习第七周(上)

    局域网的优点:具有广播功能,从一个站点可以方便的访问全网,局域网上的主机可共享连接在局域网上的各种资源:便于系统的扩展和逐渐地演变,各设备的位置可灵活调整和改变:提高了系统的可靠性.可用性和生存性. ...

  6. linux创建桌面快捷方式

    这里拿postman举例,其他的程序类似 在/usr/sharp/applications新建postman.desktop文件(终端下输入vim /usr/sharm/applications/po ...

  7. 在.NET Core使用TimeZone将客户端时间转服务器本地时间但编译提示已过期

    当我们的项目国际化后,需要处理时区问题. 在.NET Core之前我们可以通过以下代码将客户端时间转换为服务端时间: DateTime serverTime = TimeZone.CurrentTim ...

  8. 如何用Github删除repository

    第一步,登陆github,一定要点开要删除的repository,再选择相应的setting: 第二步,下拉选择,delete this repository 第三步,输入删除的仓库名,删除repos ...

  9. 安卓websocket 封装基于Java-websocket

    本文借鉴于https://blog.csdn.net/u013872857/article/details/79190643感谢大神的贡献 借鉴文章所用websocket 第三方是:nv-websoc ...

  10. bat实现往hosts文件追加内容

    做个笔记. @echo off ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::: ...