恩,这区间范围挺大的,需要离散化。如果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. LeetCode-7-反转整数-c# 版本

    c# 版本 // 给定一个 32 位有符号整数,将整数中的数字进行反转. public class Solution { public int Reverse(int x) { / // 边界判断 / ...

  2. 解决安装TensorFlow GPU缺少文件的一个比较终极的办法

    可能的报错信息 TensorFlow 下,导入这份配置的时候 python 停止运行 ImportError: DLL load failed: 找不到指定的模块 或 ImportError: No ...

  3. Vue2leaflet 替换国内地图api,带{z}/{x}/{y}形式的

    参考:https://www.cnblogs.com/gispathfinder/p/9535685.html Vue2leaflet安装后,默认自带的地图URL如下 url:'http://{s}. ...

  4. 3#Java案例

    以下内容引用Github地址https://github.com/DuGuQiuBai/Java/blob/master/day01/code/02_%E5%B8%A6%E6%B3%A8%E9%87% ...

  5. aos.css 动画效果

    aos网址 https://codepen.io/michalsnik/pen/WxNdvq <div class="item" data-aos="fade-up ...

  6. CCF CSP 201512-1 数位之和

    题目链接:http://118.190.20.162/view.page?gpid=T37 问题描述 试题编号: 201512-1 试题名称: 数位之和 时间限制: 1.0s 内存限制: 256.0M ...

  7. linux中的strings命令

     strings - print the strings of printable characters in files.            意思是, 打印文件中可打印的字符.  我来补充一下吧 ...

  8. 《CSS世界》读书笔记(十四)

    <!--  <CSS世界>张鑫旭著 --> 功勋卓越的 border 属性 border-width 不支持百分比值 border-style 类型 border-style ...

  9. get 和 post 请求的区别,一个不错的链接

    https://www.cnblogs.com/logsharing/p/8448446.html

  10. 代码修改WinForm datagridview 样式 及数据绑定

    #region 表格设置 /// <summary> /// 调整表格 /// </summary> /// <param name="dataGrid&quo ...