BZOJ原题链接

洛谷原题链接

又是扫描线,题解可看大佬的博客(太懒了不想打)

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int N = 1e5 + 10;
  5. const long long mod = 2147483648LL;
  6. struct dd {
  7. int x, y;
  8. };
  9. dd a[N];
  10. int ls_x[N], ls_y[N], sx[N], sy[N], S[N], C[N][12], nwy[N], la[N], xl, yl;
  11. inline int re()
  12. {
  13. int x = 0;
  14. char c = getchar();
  15. bool p = 0;
  16. for (; c < '0' || c > '9'; c = getchar())
  17. p |= c == '-';
  18. for (; c >= '0' && c <= '9'; c = getchar())
  19. x = x * 10 + c - '0';
  20. return p ? -x : x;
  21. }
  22. inline int MOD(long long x)
  23. {
  24. if (x < mod)
  25. return x;
  26. return x % mod;
  27. }
  28. inline int lowbit(int x) { return x & -x; }
  29. inline void add(int x, int y)
  30. {
  31. for (; x <= yl; x += lowbit(x))
  32. S[x] = MOD(1LL * S[x] + y);
  33. }
  34. inline int ask(int x)
  35. {
  36. int s = 0;
  37. for (; x; x -= lowbit(x))
  38. s = MOD(1LL * s + S[x]);
  39. return s;
  40. }
  41. bool comp(dd x, dd y)
  42. {
  43. if (!(x.x ^ y.x))
  44. return x.y < y.y;
  45. return x.x < y.x;
  46. }
  47. inline int minn(int x, int y) { return x < y ? x : y; }
  48. inline int BSX(int x)
  49. {
  50. int l = 1, r = xl, mid;
  51. while (l <= r)
  52. {
  53. mid = (l + r) >> 1;
  54. if (!(ls_x[mid] ^ x))
  55. return mid;
  56. ls_x[mid] > x ? r = mid - 1 : l = mid + 1;
  57. }
  58. return 0;
  59. }
  60. inline int BSY(int x)
  61. {
  62. int l = 1, r = yl, mid;
  63. while (l <= r)
  64. {
  65. mid = (l + r) >> 1;
  66. if (!(ls_y[mid] ^ x))
  67. return mid;
  68. ls_y[mid] > x ? r = mid - 1 : l = mid + 1;
  69. }
  70. return 0;
  71. }
  72. int main()
  73. {
  74. int i, j, n, m, s, o, v, an = 0;
  75. re(); re();
  76. n = re();
  77. for (i = 1; i <= n; i++)
  78. {
  79. ls_x[i] = a[i].x = re() + 1;
  80. ls_y[i] = a[i].y = re() + 1;
  81. }
  82. m = re();
  83. sort(ls_x + 1, ls_x + n + 1);
  84. sort(ls_y + 1, ls_y + n + 1);
  85. ls_x[n + 1] = ls_y[n + 1] = -1;
  86. for (i = 1; i <= n; i++)
  87. if (ls_x[i] ^ ls_x[i + 1])
  88. ls_x[++xl] = ls_x[i];
  89. for (i = 1; i <= n; i++)
  90. if (ls_y[i] ^ ls_y[i + 1])
  91. ls_y[++yl] = ls_y[i];
  92. for (i = 1; i <= n; i++)
  93. {
  94. a[i].x = BSX(a[i].x);
  95. a[i].y = BSY(a[i].y);
  96. sx[a[i].x]++;
  97. sy[a[i].y]++;
  98. }
  99. sort(a + 1, a + n + 1, comp);
  100. for (C[0][0] = 1, i = 1; i <= n; i++)
  101. for (j = C[i][0] = 1, o = minn(i, m); j <= o; j++)
  102. C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  103. for (i = 1; i <= n; i++)
  104. {
  105. if (a[i].x ^ a[i - 1].x)
  106. s = 0;
  107. else
  108. {
  109. s++;
  110. an = MOD(an + MOD(1LL * MOD(1LL * ask(a[i].y - 1) - ask(a[i - 1].y)) * MOD(1LL * C[s][m] * C[sx[a[i].x] - s][m])));
  111. }
  112. nwy[o = a[i].y]++;
  113. v = MOD(1LL * C[nwy[o]][m] * C[sy[o] - nwy[o]][m]);
  114. add(o, v - la[o]);
  115. la[o] = v;
  116. }
  117. printf("%lld", (1LL * an + mod) % mod);
  118. return 0;
  119. }

BZOJ1227或洛谷2154 [SDOI2009]虔诚的墓主人的更多相关文章

  1. [洛谷P2154] SDOI2009 虔诚的墓主人

    问题描述 小W是一片新造公墓的管理人.公墓可以看成一块N×M的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地. 当地的居民都是非常虔诚的基督徒,他们愿意提前为自己找一块合适墓地. ...

  2. Luogu 2154 [SDOI2009]虔诚的墓主人

    弄了很久,状态很烂…… 首先发现可用的点一共只有$1e5$个,所以可以离散化坐标来方便计算. 发现对于一个空格,设它的上.下.左.右分别有$u, d, l, r$个点,它产生的贡献是$\binom{u ...

  3. 【BZOJ1227】[SDOI2009]虔诚的墓主人(线段树)

    [BZOJ1227][SDOI2009]虔诚的墓主人(线段树) 题面 BZOJ 洛谷 题解 显然发现答案就是对于每一个空位置,考虑上下左右各有多少棵树,然后就是这四个方向上树的数量中选\(K\)棵出来 ...

  4. BZOJ1227 SDOI2009 虔诚的墓主人【树状数组+组合数】【好题】*

    BZOJ1227 SDOI2009 虔诚的墓主人 Description 小W 是一片新造公墓的管理人.公墓可以看成一块N×M 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地. ...

  5. bzoj1227 [SDOI2009]虔诚的墓主人(组合公式+离散化+线段树)

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec  Memory Limit: 259 MBSubmit: 803  Solved: 372[Submit][Statu ...

  6. bzoj1227 P2154 [SDOI2009]虔诚的墓主人

    P2154 [SDOI2009]虔诚的墓主人 组合数学+离散化+树状数组 先看题,结合样例分析,易得每个墓地的虔诚度=C(正左几棵,k)*C(正右几棵,k)*C(正上几棵,k)*C(正下几棵,k),如 ...

  7. [BZOJ1227][SDOI2009]虔诚的墓主人 组合数+树状数组

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec  Memory Limit: 259 MBSubmit: 1433  Solved: 672[Submit][Stat ...

  8. 【LG2154】[SDOI2009]虔诚的墓主人

    [LG2154][SDOI2009]虔诚的墓主人 题面 洛谷 题解 如果您没有看懂题,请反复阅读题面及样例 可以发现,对于某一个点,它的答案就是上下左右几个组合数乘起来. 这样直接做复杂度显然爆炸,考 ...

  9. BZOJ 1227: [SDOI2009]虔诚的墓主人

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec  Memory Limit: 259 MBSubmit: 1078  Solved: 510[Submit][Stat ...

随机推荐

  1. centos 安装mysql数据库

    在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1 下载并安装MySQL官方的 Yum Re ...

  2. tensorflow serving 中 No module named tensorflow_serving.apis,找不到predict_pb2问题

    最近在学习tensorflow serving,但是运行官网例子,不使用bazel时,发现运行mnist_client.py的时候出错, 在api文件中也没找到predict_pb2,因此,后面在网上 ...

  3. SPSS-聚类分析

    聚类分析(层次聚类分析(Q型聚类和R型聚类).快速聚类分析) 聚类分析的实质:是建立一种分类方法,它能够将一批样本数据按照他们在性质上的亲密程度在没有先验知识的情况下自动进行分类.这里所说的类就是一个 ...

  4. Python str list to list

    eg1: My csv data like this below,i wt count list nums 2018上,"['C', 'B', 'B', 'B', 'D', 'A', 'B' ...

  5. Using Fetch

    [Using Fetch] This kind of functionality was previously achieved using XMLHttpRequest. Fetch provide ...

  6. easymock单元测试跟踪工具

    EasyMock can save a lot of legwork and make unit tests a lot faster to write. builder.com Java E-New ...

  7. NumPy 切片和索引

    NumPy 切片和索引 ndarray对象的内容可以通过索引或切片来访问和修改,与 Python 中 list 的切片操作一样. ndarray 数组可以基于 0 - n 的下标进行索引,切片对象可以 ...

  8. 201. Bitwise AND of Numbers Range (Bit)

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND(按位与) of all nu ...

  9. 【mybatis基础】mybatis开发dao两种方法

    mybatis是一个支持普通SQL查询,存储过程和高级映射的优秀的持久层的框架,是apache下的顶级项目.mybatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.mybat ...

  10. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)

    "Oh, There is a bipartite graph.""Make it Fantastic."X wants to check whether a ...