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 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地. ...
随机推荐
- java并发笔记之synchronized 偏向锁 轻量级锁 重量级锁证明
警告⚠️:本文耗时很长,先做好心理准备 本篇将从hotspot源码(64 bits)入手,通过分析java对象头引申出锁的状态:本文采用大量实例及分析,请耐心看完,谢谢 先来看一下hotspot的 ...
- 从零开始react实战:云书签-1 react环境搭建
总览篇:react 实战之云书签 本篇是实战系列的第一篇,主要是搭建 react 开发环境,在create-react-app的基础上加上如下功能: antd 组件库按需引入 ,支持主题定制 支持 l ...
- WPF滑块控件(Slider)的自定义样式
前言 每次开发滑块控件的样式都要花很久去读样式代码,感觉有点记不牢,所以特此备忘. 自定义滑块样式 首先创建项目,添加Slider控件. 然后获取Slider的Window样式,如下图操作. 然后弹出 ...
- DES、3DES、AES、PBE对称加密算法实现及应用
1.对称加密算法概述 对称加密算法是应用较早的加密算法,技术成熟.在对称加密算法中,数据发信方将明文和加密密钥一起经过特殊加密算法处理后,使其变成复杂的加密密文发送出去.收信方收到密文后,若想解读原文 ...
- 补充Java面试记录
补充Java面试记录 背景:这两天面试遇到的部分问题都分散在了前面两篇文摘中,这里再做一些其他的记录,以备不时之需! 一.谈谈你对SpringBoot的理解? SpringBoot简介:SpringB ...
- Why do I write a blog
I believe the most beautiful and elegant answer to this question is from Churchill. "On a peace ...
- Assign the task HDU - 3974 (dfs序 + 线段树)
有一家公司有N个员工(从1到N),公司里每个员工都有一个直接的老板(除了整个公司的领导).如果你是某人的直接老板,那个人就是你的下属,他的所有下属也都是你的下属.如果你是没有人的老板,那么你就没有下属 ...
- 冬天苹果笔记macbookpro消除静电的方法
冬天mac除静电的方法 1.mac虽然声称不需要关机,但和apple技术人员沟通后,还是需要1周进行一次关机操作 2.知乎上的回答:https://www.zhihu.com/question/195 ...
- cs224d---词向量表示
1 Word meaning 1. 1 word meaning的两种定义 Definition meaning:单词的含义指代了客观存在的具体事物,如眼镜. Distributional simil ...
- 【转】linux tar.gz zip 解压缩 压缩命令
http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...