Solution

离散化 扫描线, 并用 $rest[i]$ 和 $cnt[i]$ 记录 第$i$列 总共有 $cnt[i]$棵常青树, 还有$rest[i]$ 没有被扫描到。

那么 第$i$ 列的方案数 为 $C(rest[i], k) * C(cnt[i]-rest[i], k)$。 乘上行上的方案数 并加入答案。

需要注意组合数要预处理, 我直接算发现$k > 2$就会WA。

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rd read()
#define R register
using namespace std; const int N = 2e5 + ; int cnt[N], sum[N], n, r, l, k, rest[N];
int vis[], ans;
int tot_x, tot_y, X[N], Y[N], c[N][]; struct node {
int x, y;
}pt[N]; vector<node> q[N]; inline int read() {
R int X = , p = ; char c = getchar();
for (; c > '' || c < ''; c = getchar())
if (c == '-') p = -;
for (; c >= '' && c <= ''; c = getchar())
X = X * + c - '';
return X * p;
} inline int lowbit(int x) {
return x & -x;
} inline void add(R int x, int d) {
for (;x <= tot_x; x += lowbit(x))
sum[x] += d;
} inline int query(R int x) {
int re = ;
for (; x; x -= lowbit(x))
re += sum[x];
return re;
} inline int fd_x(R int x) {
return lower_bound(X + , X + + tot_x, x) - X;
} inline int fd_y(R int y) {
return lower_bound(Y + , Y + + tot_y, y) - Y;
} inline int cmp(const node &A, const node &B) {
return A.y == B.y ? A.x < B.x : A.y < B.y;
} inline int C(int x) {
return c[x][k];
} int work(int x) {
int len = q[x].size(), re = ;
for (R int j = k - ; j <= len - k - ; ++j) {
int L = q[x][j].x, r = q[x][j + ].x;
int tmp = query(r - ) - query(L);
re += tmp * C(j + ) * C(len - j - );
}
for (R int j = ; j < len; ++j) {
int tmp = C(rest[q[x][j].x]) * C(cnt[q[x][j].x] - rest[q[x][j].x]);
add(q[x][j].x, -tmp);
rest[q[x][j].x]--;
tmp = C(rest[q[x][j].x]) * C(cnt[q[x][j].x] - rest[q[x][j].x]);
add(q[x][j].x, tmp);
}
return re;
} void init() {
c[][] = ;
for (int i = ; i <= n; ++i) {
c[i][] = ;
for (int j = ; j <= min(k, i); ++j)
c[i][j] = c[i - ][j - ] + c[i - ][j];
}
} int main()
{
r = rd, l = rd; n = rd;
for (R int i = ; i <= n; ++i) {
pt[i].x = rd, pt[i].y = rd;
X[++tot_x] = pt[i].x;
Y[++tot_y] = pt[i].y;
}
k = rd;
init();
sort(X + , X + + tot_x);
sort(Y + , Y + + tot_y);
tot_x = unique(X + , X + + tot_x) - X - ;
tot_y = unique(Y + , Y + + tot_y) - Y - ;
sort(pt + , pt + + n, cmp);
for (R int i = ; i <= n; ++i) {
pt[i].x = fd_x(pt[i].x);
pt[i].y = fd_y(pt[i].y);
cnt[pt[i].x]++;
q[pt[i].y].push_back(pt[i]);
}
for (R int i = ; i <= tot_x; ++i)
rest[i] = cnt[i];
for (R int i = ; i <= tot_y; ++i)
ans += work(i);
printf("%d\n", ans & 0x7fffffff);
}

BZOJ 1227 [SDOI2009]虔诚的墓主人 - 扫描线的更多相关文章

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

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

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

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

  3. 【以前的空间】bzoj 1227 [SDOI2009]虔诚的墓主人

    题解:hzw大神的博客说的很清楚嘛 http://hzwer.com/1941.html 朴素的做法就是每个点如果它不是墓地那么就可形成十字架的数量就是这个c(点左边的树的数量,k)*c(点右边的树的 ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 定时删除文件夹"$1"下最后修改时间大于当前时间"$2"天的文件

    shell 脚本: #!/bin/bash now=`date "+%Y-%m-%d_%H:%M:%S"`      #获取当前时间 echo "当前时间: " ...

  2. scrapy爬虫的编写步骤

    scrapy的步骤: a.编写item,爬取的各个属性 b.编写spider,name 要和 scrapy crawl xxspider一致,里面编写parse的信息,就是xpath获取item的各个 ...

  3. CSS 美化radio checkbox

    CSS 样式 <style type="text/css"> .option-input { -webkit-appearance: none; -moz-appear ...

  4. java程序中中常用到的linux操作

    1.解压命令 tar -zxvf filename.tar.gz 其中zxvf含义分别如下 z: gzip      压缩格式 x: extract  解压 v: verbose 详细信息 2.lin ...

  5. idea 修改 使用的git账号

    打开控制面板-->用户账户-->凭证管理器 如下图点击进入,删除原有的账号 当在idea中再提交或下载代码时,就会弹出如下提示框: 重新输入你自己的账号就可以了.

  6. 加载 AssetBundle 的四种方法

    [加载 AssetBundle 的四种方法] 1.AssetBundle.LoadFromMemoryAsync(byte[] binary, uint crc = 0); 返回AssetBundle ...

  7. python-ceilometerclient命令行(终结)

    ceilometerclient入口 工程ceilometerclient shell.py中的main方法 ceilometerclient目录 --ceilometerclient --commo ...

  8. 解题(JuZhengCalculate-矩阵乘法计算量)

    题目描述 矩阵乘法的运算量与矩阵乘法的顺序强相关. 例如: A是一个50×10的矩阵,B是10×20的矩阵,C是20×5的矩阵 计算A*B*C有两种顺序:((AB)C)或者(A(BC)),前者需要计算 ...

  9. Linux 永久PATH环境变量

    在/etc/profile文件中添加变量[对所有用户生效(永久的)] 用vim在文件/etc/profile文件中增加变量,该变量将会对Linux下所有用户有效,并且是“永久的”. 例如:编辑/etc ...

  10. rdlc报表的导出及预览时表头

    感谢各路大神的博客,总结rdlc报表中目前用到的知识,积累. 一.rdlc报表PDF打印出现空白页 1.先至Report.rdlc報表設計的頁面,選擇功能表上的[報表]->[報表屬性],在[配置 ...