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 ...
随机推荐
- mysql DML DDL DCL
DML(data manipulation language): 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言 D ...
- CENTOS6.6下mysql5.7.11的percona-xtrabackup安装与备份
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn Xtrabackup有两个主要的工具:xtrabackup.inno ...
- Redis入门_下
本文主要介绍redis一些高级特性. 1.Redis HyperLogLog Redis HyperLogLog 是用来做基数统计的算法,HyperLogLog 的优点是,在输入元素的数量或者体积非常 ...
- maven项目打包的时候,*Mapper.xml 文件会打不不进去解决办法
打包的时候,不同版本的 Eclipse 还有IDEA 会有打包打不进去Mapper.xml 文件,这个时候要加如下代码, 在<build> 标签内加入即可 <resources> ...
- 基于agenda的Nodejs定时任务管理框架搭建
0.背景 在大型项目中,定时任务的应用场景越来越广.一般来说,按照微服务的思想,我们会将定时任务单独部署一套服务,核心的业务接口独立到另一个服务中,从而降低相互之间的耦合程度.在需要使用定时任务时,只 ...
- linux 管理权限
linux 管理权限 linux 文件 权限 1.使用 ls -l 命令 执行结果如下(/var/log) : drwxr-x--- 2 root adm 4096 2013-08-07 11:03 ...
- Java多线程推荐使用的停止方法和暂停方法
判断线程结束和让线程结束 package cn.lonecloud.Thread.study; /** * 用于循环1000次的线程 * @Title: Run1000Thread.java * @P ...
- try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后?
这是一道面试题,首先finally{}里面的code肯定是会执行的,至于在return前还是后, 看答案说的是在return后执行,我觉得不对,百度了一下,有说return前的,有说return后的, ...
- 试着简单易懂记录synchronized this object Class的区别,模拟ConcurrentHashMap
修饰静态方法默认获取当前class的锁,同步方法没有释放的锁,不影响class其他非同步方法的调用,也不影响不同锁的同步方法,更不影响使用class的其他属性. package thread.base ...
- Mybatis的基本使用
.什么是Mybatis? Mybatis:根据官方解释,MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手工设置参数以及 ...