P2154 [SDOI2009]虔诚的墓主人 树状数组
题意
在一个坐标系中,有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]虔诚的墓主人 树状数组的更多相关文章
- Bzoj 1227: [SDOI2009]虔诚的墓主人 树状数组,离散化,组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 895 Solved: 422[Submit][Statu ...
- [luogu2154 SDOI2009] 虔诚的墓主人(树状数组+组合数)
传送门 Solution 显然每个点的权值可以由当前点上下左右的树的数量用组合数\(O(1)\)求出,但这样枚举会T 那么我们考虑一段连续区间,对于一行中两个常青树中间的部分左右树的数量一定,我们可用 ...
- BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...
- bzoj1227 P2154 [SDOI2009]虔诚的墓主人
P2154 [SDOI2009]虔诚的墓主人 组合数学+离散化+树状数组 先看题,结合样例分析,易得每个墓地的虔诚度=C(正左几棵,k)*C(正右几棵,k)*C(正上几棵,k)*C(正下几棵,k),如 ...
- [洛谷P2154] SDOI2009 虔诚的墓主人
问题描述 小W是一片新造公墓的管理人.公墓可以看成一块N×M的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地. 当地的居民都是非常虔诚的基督徒,他们愿意提前为自己找一块合适墓地. ...
- P2154 [SDOI2009]虔诚的墓主人
略有一点点思维的题. 首先,如果一个点上,下,左,右分别有\(a,b,c,d\)棵树,那这个点的十字架方案为\(C_{a}^{k}C_{b}^{k}C_{c}^{k}C_{d}^{k}\). 按x坐标 ...
- luogu P2154 [SDOI2009]虔诚的墓主人
luogu 下面记一个点上下左右点数分别为\(u_i,d_i,l_i,r_i\) 枚举每个中间点太慢了,考虑枚举两个点之间横的一条线段,这里面的点左边点数目都相同,右边点数目都相同,然后只要查一下区间 ...
- [BZOJ1227][SDOI2009]虔诚的墓主人 组合数+树状数组
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 1433 Solved: 672[Submit][Stat ...
- BZOJ1227 SDOI2009 虔诚的墓主人【树状数组+组合数】【好题】*
BZOJ1227 SDOI2009 虔诚的墓主人 Description 小W 是一片新造公墓的管理人.公墓可以看成一块N×M 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地. ...
随机推荐
- git远程服务器回滚
1.git log查找commit hash 2.git reset --hard hash 回滚本地git库 3.git push -f origin(git仓库的url) branch名 强制提交
- 计算机网络中IP地址和MAC地址
计算机 网络中的网络地址有I P 地址和物理地址之分,对 于主机间的通信时,它们的作用也不一样 . l I P 地址 为 了保证 I n t e r n e t 网上主机通信时能够相互识别 ,不引 ...
- Thinkphp5.0快速入门笔记(2)
学习来源与说明 https://www.kancloud.cn/thinkphp/thinkphp5_quickstart 测试与部署均在windows10下进行学习. 示例建立新的模块和控制器 在a ...
- Unity经典游戏教程之:弓之骑士
版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...
- jQuery插件之路(一)——试着给jQuery的一个Carousel插件添加新的功能
前几日在网上看到了一个关于Carousel插件的教学视频,于是也顺便跟着学习着做了一下.但是在做完之后发现,在别的网站上面看到类似的效果要比现在做的这个要多一个功能,也就是在底下会有一些按钮,当鼠标放 ...
- java并发编程(十二)----(JUC原子类)数组类型介绍
上一节我们介绍过三个基本类型的原子类,这次我们来看一下数组类型: AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray.其中前两个的使用方 ...
- [原创实践]RedHat Enterprise Linux 5 安装GCC和redis
Redis的安装需要使用GCC,Red Hat Enterprise 5默认是不安装gcc的,需要自己手动安装. 1:查看系统中是否有gcc gcc -v 查看本机linux版本 lsb_releas ...
- 【0731 | Day 5】Python基础(三)
Part 10 格式化输出的三种方式 一.占位符 #一般字符串连接/普通形式 name = 'Adela' age = str(22) print('My name is '+ name+ ',' ...
- git语句(后续补充)
如果你是windows用户,需要下载一个git应用程序,一路点就行,没有什么需要注意的地方 安装完成后在任一文件夹内右键都有显示,单击git bash here即可 简易的命令行入门教程: Git 全 ...
- js动态添加<tr><td>
<form id="addNewsFormData" name="addNewsFormData" isCheck="true" ac ...