hdu5820 Lights
主席树 但是能够想到题解的做法很难
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm> using namespace std; const int MAXN = 500010;
int n;
vector<int> p[50010];
int T[50010];
struct Node{
int s;
int ls, rs;
}tree[MAXN * 16];
int tot;
int x[50010];
int add(int x,int l,int r,int pre) {
int rt = ++tot;
tree[rt] = tree[pre];
tree[rt].s ++;
if(l == r) return rt;
int m = (l+r) >>1;
if(x <= m) tree[rt].ls = add(x,l,m,tree[pre].ls);
else tree[rt].rs = add(x,m+1,r,tree[pre].rs);
return rt;
}
int query(int s,int t,int l, int r, int rt1, int rt2){
if(s <= l && r <= t) return tree[rt2].s-tree[rt1].s;
int m = (l+r) >>1;
int ans = 0; if(s <= m) ans += query(s,t,l,m,tree[rt1].ls,tree[rt2].ls);
if(t > m) ans += query(s,t,m+1,r,tree[rt1].rs,tree[rt2].rs);
return ans;
} void init()
{
for (int i = 1; i <= 50000; ++i) p[i].clear();
while (n--) {
int x, y;
scanf("%d%d", &x, &y);
p[x].push_back(y);
}
for (int i = 1; i <= 50000; ++i) {
sort(p[i].begin(), p[i].end());
p[i].erase(unique(p[i].begin(), p[i].end()), p[i].end());
}
} bool solve()
{
tot = 0;
tree[0].ls = tree[0].rs = tree[0].s = 0; T[0] = 0;
memset(x, 0, sizeof(x));
for (int i = 1; i <= 50000; ++i) {
T[i] = T[i - 1];
for (int j = 0; j < (int)p[i].size(); ++j) {
int l = j == 0 ? 0 : p[i][j - 1];
int r = j == (int)p[i].size() - 1 ? 50001 : p[i][j + 1];
if (query( l + 1, r - 1,1,50000,T[i], T[x[p[i][j]]])) {
return false;
}
}
for (int j = 0; j < (int)p[i].size(); ++j) {
T[i] = add(p[i][j], 1, 50000, T[i]);
x[p[i][j]] = i;
}
}
return true;
} int main()
{
// freopen("1012.in","r",stdin);
while (scanf("%d", &n), n > 0) {
init();
puts(solve() ? "YES" : "NO");
}
}
hdu5820 Lights的更多相关文章
- HDOJ 4770 Lights Against Dudely
状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights
[我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...
- poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8481 Accepted: 5479 Description In an ...
- ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector
NBUT 1646 Internet of Lights and Switches Time Limit:5000MS Memory Limit:65535KB 64bit IO Fo ...
- HDU 4770 Lights Against DudelyLights
Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Traffic Lights
Traffic Lights time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- [BZOJ1659][Usaco2006 Mar]Lights Out 关灯
[BZOJ1659][Usaco2006 Mar]Lights Out 关灯 试题描述 奶牛们喜欢在黑暗中睡觉.每天晚上,他们的牲口棚有L(3<=L<=50)盏灯,他们想让亮着的灯尽可能的 ...
- HDU 4770 Lights Against Dudely
Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights
A. Mashmokh and Lights time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- Java 常用List集合使用场景分析
Java 常用List集合使用场景分析 过年前的最后一篇,本章通过介绍ArrayList,LinkedList,Vector,CopyOnWriteArrayList 底层实现原理和四个集合的区别.让 ...
- 洛谷 [P3398] 仓鼠找sugar
树剖求LCA 我们可以发现,两条路径ab,cd相交,当且仅当 dep[lca(a,b)]>=dep[lca(c,d)]&(lca(lca(a,b),c)==lca(a,b)||lca(l ...
- POJ 3689 Apocalypse Someday [数位DP]
Apocalypse Someday Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 1807 Accepted: 87 ...
- JS中的内置对象简介与简单的属性方法
JS中的数组: 1.数组的概念: 数组是在内存中连续存储的多个有序元素的结构,元素的顺序称为下标,通过下标查找对应元素 2.数组的声明: ①通过字面量声明var arr1 = [,,,,] JS中同一 ...
- zabbix客户端一键安装脚本(主动模式监控)
#!/bin/bash basepath=$(cd `dirname $0`; pwd)SHELL_DIR="${basepath}/shell"PACKAGE_DIR=" ...
- 洛谷P1783 海滩防御 分析+题解代码
洛谷P1783 海滩防御 分析+题解代码 题目描述: WLP同学最近迷上了一款网络联机对战游戏(终于知道为毛JOHNKRAM每天刷洛谷效率那么低了),但是他却为了这个游戏很苦恼,因为他在海边的造船厂和 ...
- 【NOIP2015】字串
[NOIP2015]字串 标签: DP NOIP Description 有两个仅包含小写英文字母的字符串 A 和 B.现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其 ...
- centos ELK安装
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn ELK是进行日志收集分析用的,具体工作.原理.作用自行google. ...
- JS原生Ajax&Jquery的Ajax技术&Json
1.介绍Ajax Ajax = 异步 JavaScript 和 XML Ajax是一种创建快速动态网页的技术 通过在后台与服务器进行少量数据交换,Ajax 可以使网页实现异步更新.这意味着可以不用整个 ...
- bzoj 1171 大sz的游戏& 2892 强袭作战 (线段树+单调队列+永久性flag)
大sz的游戏 Time Limit: 50 Sec Memory Limit: 357 MBSubmit: 536 Solved: 143[Submit][Status][Discuss] Des ...