传送门

Luogu

解题思路

离散化没什么好说

有一种暴力的想法就是枚举每一个坟墓,用一些数据结构维护一下这个店向左,向右,向上,向下的常青树的个数,然后用组合数统计方案。

但是网格图边长就有 \(1e9\) 级别,于是这种方法就萎了。

考虑从常青树下手。

我们可以发现在同一竖排中的两颗相邻的常青树之间的坟墓在纵方向的贡献是一样的。

所以我们维护每一竖排的常青树,每一横排的贡献用线段树维护即可。

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <vector>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} typedef long long LL;
const LL p = 2147483648;
const int _ = 100010; int n, k, c[12][_];
int xx, yy, X[_], Y[_];
vector < int > vec[_];
struct node{ int x, y; }t[_];
int sum[_ << 2], R[_ << 2], L[_ << 2], val[_]; inline int lc(int rt) { return rt << 1; } inline int rc(int rt) { return rt << 1 | 1; } inline void pushup(int rt) { sum[rt] = (sum[lc(rt)] + sum[rc(rt)]) % p; } inline void build(int rt = 1, int l = 1, int r = yy) {
if (l == r) { R[rt] = val[l]; return ; }
int mid = (l + r) >> 1;
build(lc(rt), l, mid), build(rc(rt), mid + 1, r);
} inline void update(int id, int rt = 1, int l = 1, int r = yy) {
if (l == r) {
--R[rt], ++L[rt], sum[rt] = 1ll * c[k][L[rt]] * c[k][R[rt]] % p;
return ;
}
int mid = (l + r) >> 1;
if (id <= mid) update(id, lc(rt), l, mid);
else update(id, rc(rt), mid + 1, r);
pushup(rt);
} inline LL query(int ql, int qr, int rt = 1, int l = 1, int r = yy) {
if (ql <= l && r <= qr) return sum[rt];
int mid = (l + r) >> 1; LL res = 0;
if (ql <= mid) res = (res + query(ql, qr, lc(rt), l, mid)) % p;
if (qr > mid) res = (res + query(ql, qr, rc(rt), mid + 1, r)) % p;
return res;
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(n), read(n);
for (rg int i = 1; i <= n; ++i) {
read(t[i].x), X[i] = t[i].x;
read(t[i].y), Y[i] = t[i].y;
}
sort(X + 1, X + n + 1), xx = unique(X + 1, X + n + 1) - X - 1;
for (rg int i = 1; i <= n; ++i) t[i].x = lower_bound(X + 1, X + xx + 1, t[i].x) - X;
sort(Y + 1, Y + n + 1), yy = unique(Y + 1, Y + n + 1) - Y - 1;
for (rg int i = 1; i <= n; ++i) t[i].y = lower_bound(Y + 1, Y + yy + 1, t[i].y) - Y;
read(k), c[0][0] = 1;
for (rg int i = 1; i <= n; ++i) {
++val[t[i].y], vec[t[i].x].push_back(t[i].y);
c[0][i] = 1;
for (rg int j = 1; j <= k; ++j)
c[j][i] = (c[j][i - 1] + c[j - 1][i - 1]) % p;
}
build();
LL res = 0;
for (rg int i = 1; i <= xx; ++i) {
sort(vec[i].begin(), vec[i].end());
if (!vec[i].empty()) update(vec[i][0]);
int siz = vec[i].size();
for (rg int j = 1; j < siz; ++j) {
if (vec[i][j - 1] + 1 <= vec[i][j] - 1 && j >= k && siz - j >= k)
res = (res + 1ll * query(vec[i][j - 1] + 1, vec[i][j] - 1) * c[k][j] % p * c[k][siz - j] % p) % p;
update(vec[i][j]);
}
}
printf("%lld\n", res);
return 0;
}

完结撒花 \(qwq\)

「SDOI2009」虔诚的墓主人的更多相关文章

  1. 「SDOI2009」Bill的挑战

    「SDOI2009」Bill的挑战 传送门 状压 \(\text{DP}\) 瞄一眼数据范围 \(N\le15\),考虑状压. 设 \(f[i][j]\) 表示在所有串中匹配到第 \(i\) 位字符且 ...

  2. 「SDOI2009」HH的项链

    「SDOI2009」HH的项链 传送门 数据加强了,莫队跑不过了. 考虑用树状数组. 先把询问按右端点递增排序. 然后对于每一种贝壳,我们都用它最右一次出现的位置计算答案. 具体细节看代码吧. 参考代 ...

  3. BZOJ 1227 【SDOI2009】 虔诚的墓主人

    Description 小W 是一片新造公墓的管理人.公墓可以看成一块 \(N×M\) 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地.当地的居民都是非常虔诚的基督徒,他们愿意 ...

  4. 「题解报告」P2154 虔诚的墓主人

    P2154 虔诚的墓主人 题解 原题传送门 题意 在 \(n\times m\) 一个方格上给你 \(w\) 个点,求方格里每个点正上下左右各选 \(k\) 个点的方案数. \(1 \le N, M ...

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

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

  6. Bzoj 1227: [SDOI2009]虔诚的墓主人 树状数组,离散化,组合数学

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

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

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

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

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

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

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

随机推荐

  1. C++-POJ1067-取石子游戏

    //(ak,bk)=([k*(1+sqrt(5))/2],[k*(1+sqrt(5))/2]+k)=(ak,ak+k) #include <cstdio> double sqrt5=2.2 ...

  2. <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes"/>

    <meta charset="utf-8" name="viewport" content="width=device-width, initi ...

  3. centos useradd 命令详解

    useradd 命令 Usage: useradd [options] LOGIN useradd -D useradd -D [options] Options: -b, --base-dir BA ...

  4. 转载:DRC

    https://cn.mathworks.com/help/audio/ug/dynamic-range-control.html?requestedDomain=cn.mathworks.com h ...

  5. Eugeny and Array(思维)

    Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to ...

  6. Sql 中获取年月日时分秒的函数

    getdate():获取系统当前时间 dateadd(datepart,number,date):计算在一个时间的基础上增加一个时间后的新时间值,比如:dateadd(yy,30,getdate()) ...

  7. Multisim 中的一些快捷键

    1.镜像 Alt + Y 2.左转90° Ctrl + L 3.右转90° Ctrl + R

  8. 脚手架搭建的react中使用bootstrap

    1.在react的index.html文件中加个jQuery的引入 <script src="http://cdn.bootcss.com/jquery/3.3.1/jquery.mi ...

  9. linux shell date的用法

    该随笔引用自https://www.cnblogs.com/alsodzy/p/8403870.html 在 linux shell 里面date命令的参数 %% 一个文字的 % %a 当前local ...

  10. Java环境配置与编译运行详解

    这篇文章主要为大家详细介绍了Java环境配置与编译运行的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 一.开篇 通过对之前Java之路的了解之后,相信初学者们都对Java有了一个比较深印 ...