题意

在一个坐标系中,有w(1e5)个点,这个图中空点的权值是正上,正下,正左,正右各取k个的排列组合情况。
计算整个图的空点权值和

思路

由于每个点的坐标是1e9级别的,所以需要先离散化。
我们考虑w个点,先按x轴排序,按y轴次排序。
从左到右枚举这w个点,
对于一个点的x值的影响,我们把它加到树状数组中做前缀和,
对于y值的影响,我们直接通过i和i+1两个点的y值计算答案。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> /* ⊂_ヽ
  \\ Λ_Λ 来了老弟
   \('ㅅ')
    > ⌒ヽ
   /   へ\
   /  / \\
   レ ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
'ノ )  Lノ */ using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c); const ll oo = 1ll<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const ll mod = ;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;} /*-----------------------showtime----------------------*/
const int maxn = 2e5+; struct node
{
int x,y;
}p[maxn];
bool cmp(node a,node b){
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
vector<int>v;
int getid(int x){
return lower_bound(v.begin(), v.end(), x) - v.begin() + ;
}
ll c[maxn][];
ll sum[maxn],cntx[maxn],cnty[maxn];
int lowbit(int x){
return x & (-x);
}
void add(int x,ll s){
while(x < maxn){
sum[x] = ((sum[x] + s) % mod + mod) % mod;;
x += lowbit(x);
}
}
ll getsum(int x){
ll res = ;
while(x > ){
res = ((res + sum[x])%mod + mod )% mod;
x -= lowbit(x);
}
return res;
}
ll Left[maxn],le_num[maxn];
int main(){
int n,m,k;
int tot;
scanf("%d%d%d", &n, &m, &tot);
for(int i=; i<=tot; i++) {
scanf("%d%d", &p[i].x, &p[i].y);
v.pb(p[i].x); v.pb(p[i].y);
}
scanf("%d", &k);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end()); c[][] = ;
for(int i=; i<; i++){
for(int j=; j<=min(i, k); j++){
if(j==||j==i) c[i][j] = ;
else c[i][j] = (c[i-][j-] + c[i-][j]) % mod;
}
} sort(p+, p++tot,cmp);
for(int i=; i<=tot; i++){
p[i].x = getid(p[i].x);
p[i].y = getid(p[i].y);
cntx[p[i].x]++;
cnty[p[i].y]++;
}
int colnum = ;
ll ans = ;
for(int i=; i<=tot; i++){ if(p[i].x != p[i-].x) colnum = ;
colnum++;
int le = p[i].y;
le_num[le] ++;
ll val = ;
if(le_num[le] >= k && cnty[le] - le_num[le] >= k){
val = c[le_num[le]][k] * c[cnty[le] - le_num[le]][k]%mod;
}
add(le, val - Left[le]); Left[le] = val;
if(p[i+].x == p[i].x &&colnum >= k && cntx[p[i].x] - colnum >= k) {
ans = (ans + c[colnum][k] * c[cntx[p[i].x] - colnum][k] % mod *(((getsum(p[i+].y - ) - getsum(p[i].y))%mod+mod)%mod)%mod)%mod;
}
}
printf("%lld\n", ans);
return ;
}

P2154 [SDOI2009]虔诚的墓主人 树状数组的更多相关文章

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

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

  2. [luogu2154 SDOI2009] 虔诚的墓主人(树状数组+组合数)

    传送门 Solution 显然每个点的权值可以由当前点上下左右的树的数量用组合数\(O(1)\)求出,但这样枚举会T 那么我们考虑一段连续区间,对于一行中两个常青树中间的部分左右树的数量一定,我们可用 ...

  3. BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...

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

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

  5. [洛谷P2154] SDOI2009 虔诚的墓主人

    问题描述 小W是一片新造公墓的管理人.公墓可以看成一块N×M的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地. 当地的居民都是非常虔诚的基督徒,他们愿意提前为自己找一块合适墓地. ...

  6. P2154 [SDOI2009]虔诚的墓主人

    略有一点点思维的题. 首先,如果一个点上,下,左,右分别有\(a,b,c,d\)棵树,那这个点的十字架方案为\(C_{a}^{k}C_{b}^{k}C_{c}^{k}C_{d}^{k}\). 按x坐标 ...

  7. luogu P2154 [SDOI2009]虔诚的墓主人

    luogu 下面记一个点上下左右点数分别为\(u_i,d_i,l_i,r_i\) 枚举每个中间点太慢了,考虑枚举两个点之间横的一条线段,这里面的点左边点数目都相同,右边点数目都相同,然后只要查一下区间 ...

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

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

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

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

随机推荐

  1. WPF 动态添加按钮以及样式字典的引用(Style introduction)

    我们想要达到的结果是,绑定多个Checkbox然后我们还可以获取它是否被选中,其实很简单,我们只要找到那几个关键的对象就可以了. 下面是Ui,其中定义了一个WrapPanel来存放CheckBox,还 ...

  2. let和const解构赋值

    1.let和const:最基础也很容易理解的,let是 声明一个变量,const是声明一个常量. 具体细节看如下实例代码 { let a=; console.log(a) } // console.l ...

  3. mysql是如何实现事务隔离以及MVCC详解

    提到事务,你肯定会想到ACID(Atomicity.Consistency.Isolation.Durability,即原子性.一致性.隔离性.持久性),我们就来说说其中I,也就是"隔离性& ...

  4. sqoop 密码别名模式 --password-alias

    sqoop要使用别名模式隐藏密码 1.首先使用命令创建别名 hadoop credential create xiaopengfei  -provider jceks://hdfs/user/pass ...

  5. 使用 Docker 生成 Let’s Encrypt 证书

    概念 什么是 Container ? https://www.docker.com/resources/what-container https://www.docker.com/why-docker ...

  6. Unity基础之:UnityAPI的学习

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  7. 后端小白的VUE入门笔记, 进阶篇

    使用 vue-cli( 脚手架) 搭建项目 基于vue-cli 创建一个模板项目 通过 npm root -g 可以查看vue全局安装目录,进而知道自己有没有安装vue-cli 如果没有安装的话,使用 ...

  8. python3学习-requests使用

    前面我们讲过了urllib模块,知道他是用于网络请求的,这一节讲的requests还是用于网络请求的,只不过urllib是官方模块,而requests是第三方的模块.用过的人都说他才是'人类使用的', ...

  9. java实现发短信功能---腾讯云短信

    目录 java实现发短信功能 前言 开发环境 腾讯云 ---短信 代码 效果 结束语 java实现发短信功能 前言 如今发短信功能已经成为互联网公司的标配,本篇文章将一步步实现java发送短信 考察了 ...

  10. python调用支付宝支付接口

    python调用支付宝支付接口详细示例—附带Django demo代码   项目演示: 一.输入金额 二.跳转到支付宝付款 三.支付成功 四.跳转回自己网站 在使用支付宝接口的前期准备: 1.支付宝公 ...