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

#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. bzoj 4836: 二元运算

    死活TLE....求助 update 4.3 23:08 求助了tls之后终于过了...分治里次数界写崩了...r-l+1就行... 分治的做法很神奇!本题的限制在于操作类型与权值相对大小有关,而用[ ...

  2. [Sdoi2017]相关分析 [线段树]

    [Sdoi2017]相关分析 题意:沙茶线段树 md其实我考场上还剩一个多小时写了40分 其实当时写正解也可以吧1h也就写完了不过还要拍一下 正解代码比40分短2333 #include <io ...

  3. python3加密解密模块 cryptography

    cryptography 的目标是成为"人类易于使用的密码学包cryptography for humans",就像 requests 是"人类易于使用的 HTTP 库H ...

  4. Linux-安装FFmpeg

    FFmpeg官网:http://www.ffmpeg.org 官网介绍 FFmpeg is the leading multimedia framework, able to decode, enco ...

  5. java-redis集合数据操作示例(三)

    redis系列博文,redis连接管理类的代码请跳转查看<java-redis字符类数据操作示例(一)>. 一.集合类型缓存测试类 public class SetTest { /** * ...

  6. Duilib第一步(III)-知识进阶

    核心模块 CWindowWnd:窗口对象管理父类 创建窗口. 窗口消息过程处理. 提供窗口子类化.超类化接口. CDialogBuilder:空间布局类 解析XML界面布局文件,构建控件树 创建控件对 ...

  7. 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)

    //1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...

  8. HDU - 2612 bfs [kuangbin带你飞]专题一

    分别以两个人的家作为起点,bfs求得到每个KFC最短距离.然后枚举每个KFC,求得时间之和的最小值即可. 此题不符合实际情况之处:  通过了一个KFC再去另一个KFC可以吗? 出题人都没好好想过吗? ...

  9. Spring cloud oauth2.0 access_token 永不失效设置方法

    在AuthorizationServerConfigurerAdapter,重写一个TokenServices,注意这里的@Primary 非常重要,否则会有3个同类型的Bean,无法注入,会抛出以下 ...

  10. Enable multi-tenancy on ironic

    Multi-tenancy 是openstack ironic从Ocata版本开始支持的新特性,通过network-generic-switch插件控制交换机,Ironic可以实现在不同租户间机网络隔 ...