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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int MAXN = 500010;
  9. int n;
  10. vector<int> p[50010];
  11. int T[50010];
  12. struct Node{
  13. int s;
  14. int ls, rs;
  15. }tree[MAXN * 16];
  16. int tot;
  17. int x[50010];
  18. int add(int x,int l,int r,int pre) {
  19. int rt = ++tot;
  20. tree[rt] = tree[pre];
  21. tree[rt].s ++;
  22. if(l == r) return rt;
  23. int m = (l+r) >>1;
  24. if(x <= m) tree[rt].ls = add(x,l,m,tree[pre].ls);
  25. else tree[rt].rs = add(x,m+1,r,tree[pre].rs);
  26. return rt;
  27. }
  28. int query(int s,int t,int l, int r, int rt1, int rt2){
  29. if(s <= l && r <= t) return tree[rt2].s-tree[rt1].s;
  30. int m = (l+r) >>1;
  31. int ans = 0;
  32.  
  33. if(s <= m) ans += query(s,t,l,m,tree[rt1].ls,tree[rt2].ls);
  34. if(t > m) ans += query(s,t,m+1,r,tree[rt1].rs,tree[rt2].rs);
  35. return ans;
  36. }
  37.  
  38. void init()
  39. {
  40. for (int i = 1; i <= 50000; ++i) p[i].clear();
  41. while (n--) {
  42. int x, y;
  43. scanf("%d%d", &x, &y);
  44. p[x].push_back(y);
  45. }
  46. for (int i = 1; i <= 50000; ++i) {
  47. sort(p[i].begin(), p[i].end());
  48. p[i].erase(unique(p[i].begin(), p[i].end()), p[i].end());
  49. }
  50. }
  51.  
  52. bool solve()
  53. {
  54. tot = 0;
  55. tree[0].ls = tree[0].rs = tree[0].s = 0; T[0] = 0;
  56. memset(x, 0, sizeof(x));
  57. for (int i = 1; i <= 50000; ++i) {
  58. T[i] = T[i - 1];
  59. for (int j = 0; j < (int)p[i].size(); ++j) {
  60. int l = j == 0 ? 0 : p[i][j - 1];
  61. int r = j == (int)p[i].size() - 1 ? 50001 : p[i][j + 1];
  62. if (query( l + 1, r - 1,1,50000,T[i], T[x[p[i][j]]])) {
  63. return false;
  64. }
  65. }
  66. for (int j = 0; j < (int)p[i].size(); ++j) {
  67. T[i] = add(p[i][j], 1, 50000, T[i]);
  68. x[p[i][j]] = i;
  69. }
  70. }
  71. return true;
  72. }
  73.  
  74. int main()
  75. {
  76. // freopen("1012.in","r",stdin);
  77. while (scanf("%d", &n), n > 0) {
  78. init();
  79. puts(solve() ? "YES" : "NO");
  80. }
  81. }

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. mysql DML DDL DCL

    DML(data manipulation language):  它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言  D ...

  2. CENTOS6.6下mysql5.7.11的percona-xtrabackup安装与备份

    本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn Xtrabackup有两个主要的工具:xtrabackup.inno ...

  3. Redis入门_下

    本文主要介绍redis一些高级特性. 1.Redis HyperLogLog Redis HyperLogLog 是用来做基数统计的算法,HyperLogLog 的优点是,在输入元素的数量或者体积非常 ...

  4. maven项目打包的时候,*Mapper.xml 文件会打不不进去解决办法

    打包的时候,不同版本的 Eclipse 还有IDEA 会有打包打不进去Mapper.xml 文件,这个时候要加如下代码, 在<build> 标签内加入即可 <resources> ...

  5. 基于agenda的Nodejs定时任务管理框架搭建

    0.背景 在大型项目中,定时任务的应用场景越来越广.一般来说,按照微服务的思想,我们会将定时任务单独部署一套服务,核心的业务接口独立到另一个服务中,从而降低相互之间的耦合程度.在需要使用定时任务时,只 ...

  6. linux 管理权限

    linux 管理权限 linux 文件 权限 1.使用 ls -l 命令 执行结果如下(/var/log) : drwxr-x--- 2 root adm 4096 2013-08-07 11:03 ...

  7. Java多线程推荐使用的停止方法和暂停方法

    判断线程结束和让线程结束 package cn.lonecloud.Thread.study; /** * 用于循环1000次的线程 * @Title: Run1000Thread.java * @P ...

  8. try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后?

    这是一道面试题,首先finally{}里面的code肯定是会执行的,至于在return前还是后, 看答案说的是在return后执行,我觉得不对,百度了一下,有说return前的,有说return后的, ...

  9. 试着简单易懂记录synchronized this object Class的区别,模拟ConcurrentHashMap

    修饰静态方法默认获取当前class的锁,同步方法没有释放的锁,不影响class其他非同步方法的调用,也不影响不同锁的同步方法,更不影响使用class的其他属性. package thread.base ...

  10. Mybatis的基本使用

    .什么是Mybatis? Mybatis:根据官方解释,MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手工设置参数以及 ...