noi.ac #36 模拟
2024-09-25 23:59:08
\(des\)
存在 \(1000 \times 1000\) 的矩阵,保证元素互不相同,\(2e5\) 次询问,每次询
问给定 \(x, y\) 问存在多少点 \((a, b)\) 满足该元素是 \(a\) 行的 \(x\) 大, \(b\)
列的 \(y\) 大。
\(sol\)
这数据范围给的不敢写暴力啊,然而这 T1 就是暴力啊
需要对所有可能的情况预处理,处理处所有可能的询问
时间复杂度 \(O(n^2logn)\)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
using namespace std;
const int N = 1010;
#define gc getchar()
#define Rep(i, a, b) for(int i = a; i <= b; i ++)
#define LL long long
inline int read() {int x = 0; char c = gc; while(c < '0' || c > '9') c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;}
inline LL readLL() {LL x = 0; char c = gc; while(c < '0' || c > '9') c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc; return x;}
int A[N][N], B[N][N];
int Sa[N][N], Sb[N][N];
int Answer[N][N];
int n, m, q;
int main() {
n = read(), m = read(), q = read();
Rep(i, 1, n) Rep(j, 1, m) A[i][j] = read();
Rep(i, 1, m) Rep(j, 1, n) B[i][j] = A[j][i];
Rep(i, 1, n) Rep(j, 1, m) Sa[i][j] = A[i][j];
Rep(i, 1, m) Rep(j, 1, n) Sb[i][j] = B[i][j];
Rep(i, 1, n) sort(Sa[i] + 1, Sa[i] + m + 1);
Rep(i, 1, m) sort(Sb[i] + 1, Sb[i] + n + 1);
Rep(i, 1, n)
Rep(j, 1, m) {
int Num = A[i][j];
int x = lower_bound(Sa[i] + 1, Sa[i] + m + 1, Num) - Sa[i];
int y = lower_bound(Sb[j] + 1, Sb[j] + n + 1, Num) - Sb[j];
int xx = m - x + 1, yy = n - y + 1;
Answer[xx][yy] ++;
}
Rep(i, 1, q) {
int x = read(), y = read();
printf("%d\n", Answer[x][y]);
}
return 0;
}
最新文章
- JS三元
- 【转】Android Paint之 setXfermode PorterDuffXfermode 讲解
- iOS开发——UI篇&;下拉弹出列表选择项效果
- [原]Unity3D深入浅出 - 认识开发环境中的自带的Package资源包
- UML 结构图之类图 总结
- CodeForces 689A -Mike and Cellphone
- 3种SQL语句分页写法
- NG2入门 - 架构
- crontab使用和格式
- Robot Framework的安装
- 页面输入的数据格式转换类:BaseAction(经常使用于Struts框架中)
- Spring加载XML机制
- [HAOI2016]找相同字符
- matplotlib使用
- python 内建函数__new__的单例模式
- Mysql 字符集及排序规则
- luogu 1640 连续攻击游戏
- Android Studio 3依赖配置
- 多线程Thread
- 转载:escape,encodeURI,encodeURIComponent有什么区别?