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 ...
随机推荐
- 【OCR技术系列之四】基于深度学习的文字识别(3755个汉字)
上一篇提到文字数据集的合成,现在我们手头上已经得到了3755个汉字(一级字库)的印刷体图像数据集,我们可以利用它们进行接下来的3755个汉字的识别系统的搭建.用深度学习做文字识别,用的网络当然是CNN ...
- BZOJ 2084: [Poi2010]Antisymmetry [Manacher]
2084: [Poi2010]Antisymmetry Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 609 Solved: 387[Submit] ...
- 初识RESTful
前言:两个月没写博客了,我真是太贱了哈哈.先简单说下我这两个月做了啥吧.8月26号从BIGO离职,回学校准备秋招.9月初时才发现已经错过秋招内推时间,其实秋招内推拿offer是有较大概率的.9月才开始 ...
- VS2012如何调试JS
下面的操作步骤描述了怎样利用vs.net中的调试器来调试javascript: 1,首先,要让你的ie允许调试脚本,具体步骤如下: 打开ie->工具菜单->inter选项->高 ...
- MySQL绿色版安装
下载MySQL绿色版 去官方下载mysql.,我下载的是 mysql-5.6.27-winx64,下载后解压缩到D:盘. 安装MySQL服务 拷贝my-default.ini重命名为my.ini,修改 ...
- mac下自带的Apache+PHP环境输出错误提示
sudo vim /etc/php.ini 找到 display_errors = Off ,把Off 改为 On . 最后为 display_errors = On ; 找到 error_repor ...
- Vijos 1404 遭遇战
Vijos 1404 遭遇战 背景 你知道吗,SQ Class的人都很喜欢打CS.(不知道CS是什么的人不用参加这次比赛). 描述 今天,他们在打一张叫DUSTII的地图,万恶的恐怖分子要炸掉藏在A区 ...
- vue.js 与iview官网
vue.js https://cn.vuejs.org/v2/guide/instance.html#生命周期图示 iview https://www.iviewui.com/components/t ...
- 知识点干货--讲一讲final、finally、finalize的区别
"横看成岭侧成峰,远近高低各不同.不识庐山真面目,只缘身在此山中." 这首诗来自于宋朝苏轼<题西林壁>,它的意思是,庐山从正面看,它是一道道连绵起伏的山岭:从侧面看,它 ...
- js使用defineProperty的一些坑
var p2={ }; Object.defineProperty(p2,"gs",{ get:function () { return this.gs; }, set:funct ...