「SDOI2009」虔诚的墓主人
传送门
Luogu
解题思路
离散化没什么好说
有一种暴力的想法就是枚举每一个坟墓,用一些数据结构维护一下这个店向左,向右,向上,向下的常青树的个数,然后用组合数统计方案。
但是网格图边长就有 \(1e9\) 级别,于是这种方法就萎了。
考虑从常青树下手。
我们可以发现在同一竖排中的两颗相邻的常青树之间的坟墓在纵方向的贡献是一样的。
所以我们维护每一竖排的常青树,每一横排的贡献用线段树维护即可。
细节注意事项
- 咕咕咕
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <vector>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
typedef long long LL;
const LL p = 2147483648;
const int _ = 100010;
int n, k, c[12][_];
int xx, yy, X[_], Y[_];
vector < int > vec[_];
struct node{ int x, y; }t[_];
int sum[_ << 2], R[_ << 2], L[_ << 2], val[_];
inline int lc(int rt) { return rt << 1; }
inline int rc(int rt) { return rt << 1 | 1; }
inline void pushup(int rt) { sum[rt] = (sum[lc(rt)] + sum[rc(rt)]) % p; }
inline void build(int rt = 1, int l = 1, int r = yy) {
if (l == r) { R[rt] = val[l]; return ; }
int mid = (l + r) >> 1;
build(lc(rt), l, mid), build(rc(rt), mid + 1, r);
}
inline void update(int id, int rt = 1, int l = 1, int r = yy) {
if (l == r) {
--R[rt], ++L[rt], sum[rt] = 1ll * c[k][L[rt]] * c[k][R[rt]] % p;
return ;
}
int mid = (l + r) >> 1;
if (id <= mid) update(id, lc(rt), l, mid);
else update(id, rc(rt), mid + 1, r);
pushup(rt);
}
inline LL query(int ql, int qr, int rt = 1, int l = 1, int r = yy) {
if (ql <= l && r <= qr) return sum[rt];
int mid = (l + r) >> 1; LL res = 0;
if (ql <= mid) res = (res + query(ql, qr, lc(rt), l, mid)) % p;
if (qr > mid) res = (res + query(ql, qr, rc(rt), mid + 1, r)) % p;
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(n), read(n);
for (rg int i = 1; i <= n; ++i) {
read(t[i].x), X[i] = t[i].x;
read(t[i].y), Y[i] = t[i].y;
}
sort(X + 1, X + n + 1), xx = unique(X + 1, X + n + 1) - X - 1;
for (rg int i = 1; i <= n; ++i) t[i].x = lower_bound(X + 1, X + xx + 1, t[i].x) - X;
sort(Y + 1, Y + n + 1), yy = unique(Y + 1, Y + n + 1) - Y - 1;
for (rg int i = 1; i <= n; ++i) t[i].y = lower_bound(Y + 1, Y + yy + 1, t[i].y) - Y;
read(k), c[0][0] = 1;
for (rg int i = 1; i <= n; ++i) {
++val[t[i].y], vec[t[i].x].push_back(t[i].y);
c[0][i] = 1;
for (rg int j = 1; j <= k; ++j)
c[j][i] = (c[j][i - 1] + c[j - 1][i - 1]) % p;
}
build();
LL res = 0;
for (rg int i = 1; i <= xx; ++i) {
sort(vec[i].begin(), vec[i].end());
if (!vec[i].empty()) update(vec[i][0]);
int siz = vec[i].size();
for (rg int j = 1; j < siz; ++j) {
if (vec[i][j - 1] + 1 <= vec[i][j] - 1 && j >= k && siz - j >= k)
res = (res + 1ll * query(vec[i][j - 1] + 1, vec[i][j] - 1) * c[k][j] % p * c[k][siz - j] % p) % p;
update(vec[i][j]);
}
}
printf("%lld\n", res);
return 0;
}
完结撒花 \(qwq\)
「SDOI2009」虔诚的墓主人的更多相关文章
- 「SDOI2009」Bill的挑战
「SDOI2009」Bill的挑战 传送门 状压 \(\text{DP}\) 瞄一眼数据范围 \(N\le15\),考虑状压. 设 \(f[i][j]\) 表示在所有串中匹配到第 \(i\) 位字符且 ...
- 「SDOI2009」HH的项链
「SDOI2009」HH的项链 传送门 数据加强了,莫队跑不过了. 考虑用树状数组. 先把询问按右端点递增排序. 然后对于每一种贝壳,我们都用它最右一次出现的位置计算答案. 具体细节看代码吧. 参考代 ...
- BZOJ 1227 【SDOI2009】 虔诚的墓主人
Description 小W 是一片新造公墓的管理人.公墓可以看成一块 \(N×M\) 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地.当地的居民都是非常虔诚的基督徒,他们愿意 ...
- 「题解报告」P2154 虔诚的墓主人
P2154 虔诚的墓主人 题解 原题传送门 题意 在 \(n\times m\) 一个方格上给你 \(w\) 个点,求方格里每个点正上下左右各选 \(k\) 个点的方案数. \(1 \le N, M ...
- BZOJ 1227: [SDOI2009]虔诚的墓主人
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 1078 Solved: 510[Submit][Stat ...
- Bzoj 1227: [SDOI2009]虔诚的墓主人 树状数组,离散化,组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 895 Solved: 422[Submit][Statu ...
- bzoj1227 [SDOI2009]虔诚的墓主人(组合公式+离散化+线段树)
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 803 Solved: 372[Submit][Statu ...
- 1227: [SDOI2009]虔诚的墓主人
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MBSubmit: 1083 Solved: 514[Submit][Stat ...
- bzoj1227 P2154 [SDOI2009]虔诚的墓主人
P2154 [SDOI2009]虔诚的墓主人 组合数学+离散化+树状数组 先看题,结合样例分析,易得每个墓地的虔诚度=C(正左几棵,k)*C(正右几棵,k)*C(正上几棵,k)*C(正下几棵,k),如 ...
随机推荐
- 快速排序 QuickSort (C++迭代,递归)
/* * QuickSort.h * 快速排序(将每一个元素转换为轴点元素) * Created on: 2020年2月12日 * Author: LuYonglei */ #ifndef SRC_Q ...
- AcWing 790. 数的三次方根
#include<bits/stdc++.h> using namespace std ; int main(){ double x; cin>>x; ,r=; ) { ; i ...
- IDEAVIM 常用快捷键总结和使用说明
---title: ideavim常用快捷键总结和使用tags: grammar_cjkRuby: true--- #### `待办` ideavim用于编程的常用快捷键说明 常用快捷键 插入(光标前 ...
- pikachu练习平台(XSS-漏洞测试案例(cookie的窃取和利用、钓鱼攻击、XSS获取键盘记录))
XSS-漏洞测试案例 xss案例 1.cookie的窃取和利用 2.钓鱼攻击 3.XSS获取键盘记录 在进行案例之前首先要搭建xss后台 搭建xss后台 1.在pikachu文件夹下面,把pkxss单 ...
- Java爬虫学习(3)之用对象保存新浪微博博文
package com.mieba; import us.codecraft.webmagic.Page; import us.codecraft.webmagic.Site; import us.c ...
- win10显示“没有有效的IP地址”
可能你没有新建该宽带连接!!!(本人就是蠢到如此地步了_(:з)∠)_)
- 使用Eclipse远程调试云服务器上的微信公众项目
云服务器系统:centos 7.3 如何在Eclipse上调试我们在云服务器上的项目呢,下面介绍一下步骤: 1.因为root账号不支持远程调试,首先需要在linux上创建一个新的用户,然后用该用户 ...
- Codeforces 1207C Gas Pipeline (dp)
题目链接:http://codeforces.com/problemset/problem/1207/C 题目大意是给一条道路修管道,相隔一个单位的管道有两个柱子支撑,管道柱子高度可以是1可以是2,道 ...
- bistoury建库建表(一)
bistoury DROP TABLE IF EXISTS bistoury_app; CREATE TABLE bistoury_app( id INT UNSIGNED auto_incremen ...
- 旋转坐标+前缀和(zqu 25001)
本题题意:在一个矩阵中,去随机一点,设定一个步数K,求出从这个点可以走到的范围的和,求最大值 思路:这个范围的和是一个菱形,我们把他旋转45°,然后成为一个正放的矩阵,求出二维前缀和 然后用前缀和的性 ...