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. SSM综合练习

    CRM系统 CRM项目外观 1. 开发环境 IDE: Eclipse Neon Release (4.6.0) Jdk: 1.8 数据库: MySQL 2. 创建数据库 创建crm数据库,这里使用的是 ...

  2. CKfinder for java详解二:缩略图及图片上传的缩放

    我们找到 <thumbs><enabled>true</enabled><url>�SE_URL%_thumbs/</url><dir ...

  3. 11.14java课堂测试

    源代码: import java.*; import java.util.*; import java.io.File; import java.io.FileInputStream; import ...

  4. CentOS 6.3开机启动服务及自动联网

    虚拟机设置选择NAT模式,默认情况下,CentOS不是自动连接上网的,要点击右上角有个电脑图标,选择system eth0进行连接, 可以修改开机启动配置只需修改:/etc/sysconfig/net ...

  5. PasteDeploy部署Pecan API 服务

    part 1:请求处理 使用PasteDeploy模块来实现 WSGI Services 时,都需要加载一个 paste.ini 文件,文件用来定义服务过滤和请求路由,类似于springMvc的拦截器 ...

  6. js实现多级复选框的交互

    功能介绍   整个复选框是包含多级,可能有父级,可能有子级,在勾选复选框时,要做两种判断: 1要判断它下面有没有子级,有子级将子级的选中状态checked变得和自己一样. 2要判断它是否有父级,有父级 ...

  7. oracle 函数的返回值与out参数

    函数的return值是调用函数返回的结果. 而out参数就是单纯的赋值. 例子: function test(aaa in varchar, bbb out integer) return integ ...

  8. CSS3 Backgrounds相关介绍

    CSS3 Backgrounds相关介绍 1.背景图片(background images)是在padding-box的左上角落脚安家的,我们可以使用background-position属性改变默认 ...

  9. 变态跳台阶(python)

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. # -*- coding:utf-8 -*- class Solution: ...

  10. stm32阅读代码工具source insight

    不知道学stm32有没有这样的烦恼,想看一个项目的代码,但是用keil又发现建立工程太麻烦,单个打开文件又找不到函数和变量之间的依赖关系,变量和函数又不能高亮显示,linux下vim和emacs虽然很 ...