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 ...
随机推荐
- Python3学习之路~7.1 静态方法、类方法、属性方法
静态方法 通过@staticmethod装饰器即可把其装饰的方法变为一个静态方法,什么是静态方法呢?其实不难理解,普通的方法,可以在实例化后直接调用,并且在方法里可以通过self.调用实例变量或类变量 ...
- 如何配置Bitbucket的ssh
在bitbucket上使用https协议,经常会在提交代码的时候出错,让人很着急上火,但是用ssh就要方便很多.下面介绍一下设置ssh的方法:1.在终端中运行ssh-keygen.2.然后一路ente ...
- 【技巧】-NO.123.数据处理技巧
Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
- 爬取豆瓣电影排行top250
功能描述V1.0: 爬取豆瓣电影排行top250 功能分析: 使用的库 1.time 2.json 3.requests 4.BuautifulSoup 5.RequestException 上机实验 ...
- OO第二单元总结(多线程的电梯调度)
经过第一单元作业的训练,在做第二单元的作业的时候,要更加的有条理.但是第二次作业多线程的运行,带来了更多的运行的不确定性.呈现出来就是程序会出现由于线程安全问题带来的不可复现的bug.本单元的作业也让 ...
- net Core TOptions和热更新
TOptions接口 net Core 项目有个appsettings.json文件,程序默认也是读取的这个文件,appsettings.json是一个配置文件 我们可以把appsettings.js ...
- 解决页面使用ifrmae后,在session失效后登录页面在子页面中显示(子窗体出现父窗体)
在登录页面中添加js判断当前页面是否是父页面,诺不是则父页面跳转至登录页面. <script type="text/javascript"> //解决登录后多个父窗体问 ...
- windows 中的类似于sudo的命令(在cmd中以另一个用户的身份运行命令)
linux中我们习惯用sudo命令来临时用另一个用户的身份执行命令. windows中,通常我们需要用管理员权限执行命令的时候通常是 右键->run as administrator. 用着键盘 ...
- Vue 组件&组件之间的通信 父子组件的通信
在Vue的组件内也可以定义组件,这种关系成为父子组件的关系: 如果在一个Vue实例中定义了component-a,然后在component-a中定义了component-b,那他们的关系就是: Vue ...
- Servlet3.0与springmvc那些事
官方文档:https://docs.spring.io/spring/docs/5.0.2.RELEASE/spring-framework-reference/web.html#mvc-servle ...