恩,这区间范围挺大的,需要离散化。如果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. Django---项目

    1.项目介绍 2.前期项目配置 3.用户注册---用户类创建和短信验证码的功能实现

  2. c++中的auto、const auto&

    先介绍一下auto.const: 在块作用域.命名作用域.循环初始化语句等等  中声明变量时,关键词auto用作类型指定符. const:修饰符 接下来我们细细分析一下: (1)auto auto即 ...

  3. 代码块: 以冒号作为开始,用缩进来划分作用域,这个整体叫做代码块,python的代码块可以提升整体的整齐度,提高开发效率

    # ### 代码块: 以冒号作为开始,用缩进来划分作用域,这个整体叫做代码块 if 5 == 5: print(1) print(2) if True: print(3) print(4) if Fa ...

  4. java mysql连接时出现的问题

    当出现Caused by: java.sql.SQLException: Unknown system variable ‘tx_isolation’ 一般是mysql-connector-java的 ...

  5. python拼接multipart/form-data类型post请求格式

    # 最近要做form-data类型接口,大多数这种格式用来文件上传,但是我们公司就是用这种格式传输请求数据. # 百度了一些基本都是files方式的,可是我们需要data=方式的.下面自己来拼接,代码 ...

  6. window安装pycharm Django

    pycharm 安装Pycharm  直接在官网下载就可以,这里说一下如何破解注册码的问题: 修改电脑中hosts文件(地址: C:\Windows\System32\drivers\etc ),改变 ...

  7. CentOS 7 Squid代理服务器反向代理

    Squid反向代理 将不同的URL请求分发到后台不同的Web服务器上,通过squid反向代理,可以加速网站的访问速度,同时互联网用户只能看到反向代理服务器的地址,加强网站的访问安全 Squid反向代理 ...

  8. mysqlworkbench访问远程服务器

    1.如果服务器有防火墙,需要关一下: systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service # ...

  9. CentOS7──xxx is not in the sudoers file

    提示"xxx is not in the sudoers file. This incident will be reported.其中 ”XXX“是你的用户名,也就是你的用户名没有权限使用 ...

  10. Angular.js指令

    ng-style   <input type="button" value="set color" ng-click="myStyle={col ...