主席树 但是能够想到题解的做法很难

#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的更多相关文章

  1. HDOJ 4770 Lights Against Dudely

    状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  2. [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights

    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...

  3. poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8481   Accepted: 5479 Description In an ...

  4. 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 ...

  5. HDU 4770 Lights Against DudelyLights

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. Traffic Lights

    Traffic Lights time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. [BZOJ1659][Usaco2006 Mar]Lights Out 关灯

    [BZOJ1659][Usaco2006 Mar]Lights Out 关灯 试题描述 奶牛们喜欢在黑暗中睡觉.每天晚上,他们的牲口棚有L(3<=L<=50)盏灯,他们想让亮着的灯尽可能的 ...

  8. HDU 4770 Lights Against Dudely

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. 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 ...

随机推荐

  1. Linux tail,cat,head命令

    tail命令用于将文件的最后部分输出到标准设备,通常是终端,也可以支持更新操作,当文档内容发生变化时,tail会自己主动刷新,确保你看到最新的档案内容. 1.tail -f filename 监视fi ...

  2. MySQL学习笔记(二)

    连接与断开服务器 应该以下面的方式连接MySQL服务器,而不是将密码以明文方式输入连接. C:\> mysql -h host -u user -pEnter password: ******* ...

  3. [Miller-Rabin & Pollard-rho]【学习笔记】

    Miller-Rabin & Pollard-rho 很久之前就学过了...今天重学一遍 利用费马小定理,但不能判断伪素数的情况 基于a的伪素数n: \(a^{n-1} \equiv 1 \p ...

  4. 游戏服务器设计之NPC系统

    游戏服务器设计之NPC系统 简介 NPC系统是游戏中非常重要的系统,设计的好坏很大程度上影响游戏的体验.NPC在游戏中有如下作用: 引导玩家体验游戏内容,一般游戏内有很多主线.支线任务,而任务的介绍. ...

  5. PhpStorm的破解 汉化

    以前一直习惯使用sublime,最近发现phpstorm比submit稍微更强大些,其很多插件都是直接可以使用,不需要另外去拓展了 其中的破解.汉化步骤就需要借助一些资源 (1)破解 安装完毕后,直接 ...

  6. PHPUnit简介及使用

    一.PHPUnit是什么? 1.它是一款轻量级的PHP测试框架,地址:http://www.phpunit.cn 2.手册:http://www.phpunit.cn/manual/5.7/zh_cn ...

  7. 排序算法(Java实现)

    这几天一直在看严蔚敏老师的那本<数据结构>那本书.之前第一次学懵懵逼逼,当再次看的时候,发觉写的是非常详细,非常的好. 那就把相关的排序算法用我熟悉的Java语言记录下来了.以下排序算法是 ...

  8. Android安全机制

    1)Android是基于Linux内核的,因此Linux对文件权限的控制同样适用于Android.在Android中每个应用都有自己的/data/data/包名文件夹,该文件夹只能该应用访问,而其他应 ...

  9. POJ - 2492 种类并查集

    思路:保存每个点与其父节点的关系,注意合并和路径压缩即可. AC代码 #include <cstdio> #include <cmath> #include <cctyp ...

  10. Ansible自动化运维笔记3(playbook)

    1.基本语法 playbook文件格式为yaml语法.示例如下: 1.1 nginx.yaml --- - hosts: all tasks: - name: Install Nginx Packag ...