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 底层实现原理和四个集合的区别.让 ...
- 深入理解Java内存模型之系列篇[转]
原文链接:http://blog.csdn.net/ccit0519/article/details/11241403 深入理解Java内存模型(一)——基础 并发编程模型的分类 在并发编程中,我们需 ...
- bind,apply,call区别总结
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- php与web页面交互
一.web表单 web表单的功能是让浏览者和网站有一个互动的平台.web表单主要用来在网页中发送数据到服务器. 1.1 表单的创建 使用form标记,并在其中插入相关的表单元素,即可创建一个表单. & ...
- python中的变量,运算符
范例: name = 'Crossin' myVar = 123 price = 5.99 visible = True “=”的作用是把右边的值赋予给左边的变量. python中有四种较为常见的数据 ...
- css为第几个倍数元素添加样式
//3n就是3的倍数都加这个样式*/.list li:nth-child(3n){ border-bottom:1px;}
- 通过读取配置文件,启动mongodb
在实际的项目中,经常利用mongodb数据库做缓存,mongodb的并发性比较高,所以对于快速存储.读取信息有很多优点.在项目中对于第一次的数据请求会直接访问数据库,而对于获得的信息通常都会在此时刻存 ...
- Java经典编程题50道之三十九
写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度. public class Example39 { public static void main(String[] a ...
- HttpClient读取数据乱码的解决方案
博主是一个近十年的老书虫了,从高中那会儿就开始看网络小说.每天半天看晚上看啊,终于眼睛也近视了,成绩也下降了(....好像说远了) 最近在追辰东的<圣墟>,最近写到精彩部分了,一直等更新. ...
- SQLite常用函数及语句
SQLite3.0使用的是C的函数接口,常用函数如下: sqlite3_open() //打开数据库 sqlite3_close() //关闭数据库 sqlite3_exec() //执行sql语句, ...