题意

在一个坐标系中,有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. 主机cpu突然飙高,如何快速排查问题

    [问题发现] 使用zabbix软件监控服务器时发现cpu突然异常,在业务主机上使用top命令查看系统的整体运行情况,使用top命令后发现mysqld占用CPU特别高,初步判断可能是mysqld出现问题 ...

  2. UIRefreshControl 问题

    这两天在学UIRefreshControl,主要参照的是github上的一个Demo(网址 https://github.com/evgeniymikholap/UIRefreshControlExa ...

  3. 虚拟机ip地址从ipv6改为ipv4相关问题

    有一次打开虚拟机时,Xshell连接不上虚拟机,就很奇怪,然后查看虚拟机的ip地址,发现显示为ipv6格式,然后总结了两种情况如下: 第一种情况: onboot为no时显示ipv6地址, 改为yes即 ...

  4. Code blocks返回错误代码:Process returned -1073741819 (0xC0000005)

    循环语句访问链表时,返回了错误代码: 逐项排查后,发现是由while循环引起的: 附上出错代码: do{ L=L->post; printf("%05d %d %05d\n" ...

  5. Superset 官方入门教程中文翻译

    本文翻译自 Superset 的官方文档:Toturial - Creating your first dashboard 最新版本的 Superset 界面与功能上与文档中提到的会有些许出入,以实际 ...

  6. Zookeeper 学习笔记(一)之功能介绍

    Zookeeper 主要在以下场景中可以使用 一,命名服务(用到了zookeeper的文件系统) 命名服务是指通过指定的名字来获取资源或者服务的地址,利用zk创建一个全局的路径,提供服务的地址或者一个 ...

  7. 100天搞定机器学习|Day15 朴素贝叶斯

    Day15,开始学习朴素贝叶斯,先了解一下贝爷,以示敬意. 托马斯·贝叶斯 (Thomas Bayes),英国神学家.数学家.数理统计学家和哲学家,1702年出生于英国伦敦,做过神甫:1742年成为英 ...

  8. Nginx + Lua 搭建网站WAF防火墙

    前言 对于项目里面只是使用代理等常用功能,在线安装即可,如需制定化模块,则推荐编译安装 PS:本文不仅仅包含Nginx相关的知识点,还包含了逆天学习方法(对待新事物的处理) 官方网站:https:// ...

  9. TensorFlow学习笔记——深层神经网络的整理

    维基百科对深度学习的精确定义为“一类通过多层非线性变换对高复杂性数据建模算法的合集”.因为深层神经网络是实现“多层非线性变换”最常用的一种方法,所以在实际中可以认为深度学习就是深度神经网络的代名词.从 ...

  10. Android:JNI与NDK(三)NDK构建的脚本文件配置

    友情提示:欢迎关注本人公众号,那里有更好的阅读体验以及第一时间获取最新文章 本文目录 一.前言 本篇我们介绍Android.mk与CMakeLists.txt构建NDK的配置文件,我们知道目前NDK的 ...