http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564

 

根据它的定义是行最小,列最大。

可以证明鞍点是唯一的。

单独考虑每一个元素的贡献,它能成为鞍点的情况有:

1、在这一行中,<= a[i][j]的元素肯定要删除,那么剩下k1个大于他a[i][j]的,当然a[i][j]本身不能删除

2、在这一列中,>= a[i][j]的元素肯定要删除,那么剩下k2个小于a[i][j]的,当然a[i][j]本身不能删除

那么,总情况就是,对于那k1个元素,对应着k1列,要么删除,要么不删除,有2^k1种情况,在k2个元素中,对应着k2列,也是要么删除,要么不删除,。有2^k2种情况,相乘就是贡献。

也就是要知道a[i][j]在当前行中,有多少个元素比它大,在当前列中,有多少个元素比它小,处理出来即可。

比赛的时候想到了bit,然后发现好像sort然后二分找即可。

越学越傻

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e6 + ;
int c[maxn];
int lowbit(int x) {
return x & (-x);
}
void upDate(int pos, int val) {
while (pos <= maxn - ) {
c[pos] += val;
pos += lowbit(pos);
}
}
int query(int pos) {
int ans = ;
while (pos) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
int a[ + ][ + ];
int row[ + ][ + ], col[ + ][ + ];
const int MOD = 1e9 + ;
LL quick_pow(LL a, LL b, LL MOD) {
LL base = a % MOD;
LL ans = ;
while (b) {
if (b & ) {
ans = (ans * base) % MOD;
}
base = (base * base) % MOD;
b >>= ;
}
return ans;
}
void work() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
scanf("%d", &a[i][j]);
}
}
memset(c, , sizeof c);
for (int i = ; i <= n; ++i) {
if (i != ) {
for (int j = ; j <= m; ++j) {
upDate(a[i - ][j], -);
}
}
for (int j = ; j <= m; ++j) {
upDate(a[i][j], );
}
for (int j = ; j <= m; ++j) {
row[i][j] = m - query(a[i][j]);
}
}
memset(c, , sizeof c);
for (int i = ; i <= m; ++i) {
if (i != ) {
for (int j = ; j <= n; ++j) {
upDate(a[j][i - ], -);
}
}
for (int j = ; j <= n; ++j) {
upDate(a[j][i], );
}
for (int j = ; j <= n; ++j) {
col[j][i] = query(a[j][i] - );
}
}
LL ans = ;
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
// printf("[%d %d] ", row[i][j], col[i][j]);
ans += quick_pow(, row[i][j], MOD) * quick_pow(, col[i][j], MOD) % MOD;
if (ans >= MOD) ans %= MOD;
}
// cout << endl;
}
// cout << endl;
printf("%lld\n", ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

bit跑了990ms。。吓死了。

ZOJ Saddle Point 数学思维题的更多相关文章

  1. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  2. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  3. zoj 2818 Root of the Problem(数学思维题)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...

  4. 51Nod 1003 阶乘后面0的数量(数学,思维题)

    1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...

  5. Gym 100801D Distribution in Metagonia (数学思维题)

    题目:传送门.(需要下载PDF) 题意:t组数据,每组数据给定一个数ni(1 ≤ ni ≤ 10^18),把ni拆成尽可能多的数,要求每个数的素因子只包含2和3,且这些数不能被彼此整除,输出一共能拆成 ...

  6. ZOJ 4060 - Flippy Sequence - [思维题][2018 ACM-ICPC Asia Qingdao Regional Problem C]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060 题意: 给出两个 $0,1$ 字符串 $S,T$,现在你有 ...

  7. BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题

    Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...

  8. BZOJ4377[POI2015]Kurs szybkiego czytania——数学思维题

    题目描述 给定n,a,b,p,其中n,a互质.定义一个长度为n的01串c[0..n-1],其中c[i]==0当且仅当(ai+b) mod n < p.给定一个长为m的小01串,求出小串在大串中出 ...

  9. EOJ2018.10 月赛(B 数学+思维题)

    传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 找到最小的包含子序列a的序列s,并且序列s是 p -莫干山序 ...

随机推荐

  1. HDU2147 kiki's game (SG表找规律)

    Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes th ...

  2. 「NOIP2002」「Codevs1099」 字串变换(BFS

    1099 字串变换 2002年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold   题目描述 Description 已知有两个字串 $A$, ...

  3. CSS:CSS 颜色十六进制值

    ylbtech-CSS:CSS 颜色十六进制值 1.返回顶部 1. 根据十六进制值排序 所有浏览器都支持的颜色名 根据颜色名排序的相同列表 颜色名 十六进制颜色值 颜色 Black #000000   ...

  4. HttpPost 传输Json数据并解析

    转自:https://blog.csdn.net/qq_35114086/article/details/52317311 这里写个测试用例模拟外部调用,通过httppost 传递一个json封装的表 ...

  5. Game with Powers

    题意: 有1~n,n个数字,两个人轮流操作,每一次一个人可以拿一个数字$x$,之后$x, x^2, x^3....x^t$全都被删掉. 给定n,问最优策略下谁赢. 解法: 考虑SG函数,可以注意到题目 ...

  6. wannafly test D

    题意: 给定n,m求满足: 1.a[i][j]互不相同,且有$1<=a[i][j]<=n*m$ 2.对于$a[i1][j1],a[i2][j2]$,如果有 $i1 \oplus j1 &g ...

  7. Eigen::Map

    http://cherishlc.iteye.com/blog/2116800 Map类 是 矩阵库Eigen中用来将内存数据 映射为 任意形状的矩阵的类.

  8. linux之打包压缩命令

    tar:主选项:[一条命令以下5个参数只能有一个]-c: --create 新建一个压缩文档,即打包-x: --extract,--get解压文件-t: --list,查看压缩文档里的文件目录-r:- ...

  9. csvreader 来操作csv文件

    http://www.cnitblog.com/rd416/archive/2010/07/08/47248.html

  10. SqlServer2012——快照

    1.数据库快照 优点: 维护历史数据以生成报表.由于数据库快照可提供数据库的静态视图,因而可以通过快照访问特定时间点的数据. 将查询实施在数据库的快照上,可以释放主体数据库上的资源. 数据库快照的限制 ...