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. VFS: Cannot open root device "nfs" or unknown-block(0,255)错误的解决

    1. 解决办法:在内核配置时候文件系统中选中Root file system on NFS

  2. JS----click3种方法

    js最常用的click事件3种方法 1.onclick=name() <!DOCTYPE html> <html leng="en"> <head&g ...

  3. SAP自开发程序

    1.显示/查找SAP所有可执行程序清单,双击事务码执行. *&----------------------------------------------------------------- ...

  4. 找回密码的url分析

    https://www.example.com/reset?email=user@example.com&key=b4c9a289323b21a01c3e940f150eb9b8c542587 ...

  5. Access sql语句创建表及字段类型(转)

    http://www.cnblogs.com/hnyei/archive/2012/02/23/2364812.html 创建一张空表: Sql="Create TABLE [表名]&quo ...

  6. openstack(Pike 版)集群部署(三)--- Glance 部署

    一.介绍 参照官网部署:https://docs.openstack.org/glance/queens/install/ 继续上一博客进行部署:http://www.cnblogs.com/weij ...

  7. minSdk(API 26) > deviceSdk(API 19)解决方式

    运行项目时出现“minSdk(API 26) > deviceSdk(API 19)”的提示,因为我用的是手机是sdk(API19)的,而项目要求是最低版本是minSdk(API 26),在我的 ...

  8. POJ3259 :Wormholes(SPFA判负环)

    POJ3259 :Wormholes 时间限制:2000MS 内存限制:65536KByte 64位IO格式:%I64d & %I64u 描述 While exploring his many ...

  9. 不要62(数位DP)

    不要62 http://acm.hdu.edu.cn/showproblem.php?pid=2089 Time Limit: 1000/1000 MS (Java/Others)    Memory ...

  10. Codeforces Beta Round #67 (Div. 2)

    Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...