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. 部署Java的运行环境

    1.先去官网下载最新的jdk 网址:http://www.oracle.com/technetwork/java/javase/downloads/ 2.用tar zxvf解压相应的文档到相应的路径 ...

  2. 自动化运维工具Ansible的部署步骤详解

    本文来源于http://sofar.blog.51cto.com/353572/1579894,主要是看到这样一篇好文章,想留下来供各位同僚一起分享. 一.基础介绍 ================= ...

  3. 大数据入门到精通1--大数据环境下的基础文件HDFS 操作

    1.使用hdfs用户或者hadoop用户登录 2.在linux shell下执行命令 hadoop fs -put '本地文件名' hadoop fs - put '/home/hdfs/sample ...

  4. wamp 安装redis扩展

    phpredis扩展下载地址  http://windows.php.net/downloads/pecl/snaps/redis/ 1.选择redis DLL文件扩展 phpinfo 查看VC版本 ...

  5. 可上下拖动且有浮沉动画的View

    package com.ifenglian.superapp1; import android.animation.Animator;import android.animation.Animator ...

  6. vue confirm确认

    this.$confirm('您确定删除吗?').then(_ => { do something ... (确认) }).catch(_ => { do something ... (取 ...

  7. Centos 7 下 Mysql 5.7 Galera Cluster 集群部署

     一.介绍 传统架构的使用,一直被人们所诟病,因为MySQL的主从模式,天生的不能完全保证数据一致,很多大公司会花很大人力物力去解决这个问题,而效果却一般,可以说,只能是通过牺牲性能,来获得数据一致性 ...

  8. 源码调用ffmpeg库时,需要注意接口为C接口

    即引用相关头文件时候,要使用extern "C"{}来包含. 关于extern "C"{}的详情,参考:http://www.cnblogs.com/skyne ...

  9. codeblocks安装(自带gcc编译器)

    下载安装自带c编译器的的codeblocks. 网址:http://www.codeblocks.org/downloads/26 自带gcc编译器的版本 codeblocks-16.01mingw- ...

  10. poj 1789 prime

    链接:Truck History - POJ 1789 - Virtual Judge  https://vjudge.net/problem/POJ-1789 题意:先给出一个n,代表接下来字符串的 ...