\(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;
}

最新文章

  1. JS三元
  2. 【转】Android Paint之 setXfermode PorterDuffXfermode 讲解
  3. iOS开发——UI篇&amp;下拉弹出列表选择项效果
  4. [原]Unity3D深入浅出 - 认识开发环境中的自带的Package资源包
  5. UML 结构图之类图 总结
  6. CodeForces 689A -Mike and Cellphone
  7. 3种SQL语句分页写法
  8. NG2入门 - 架构
  9. crontab使用和格式
  10. Robot Framework的安装
  11. 页面输入的数据格式转换类:BaseAction(经常使用于Struts框架中)
  12. Spring加载XML机制
  13. [HAOI2016]找相同字符
  14. matplotlib使用
  15. python 内建函数__new__的单例模式
  16. Mysql 字符集及排序规则
  17. luogu 1640 连续攻击游戏
  18. Android Studio 3依赖配置
  19. 多线程Thread
  20. 转载:escape,encodeURI,encodeURIComponent有什么区别?

热门文章

  1. Codeforces Round #570 Div. 3
  2. java 单链表反转
  3. 基于【 springBoot +springCloud+vue 项目】一 || 后端搭建
  4. php生成一维码以及保存-转载
  5. 在SQL查询结果中添加自增列的两种方法
  6. java线程的生命周期及五种基本状态
  7. c# System.Collections接口图
  8. ssmtp脚本发中文邮件的笔记
  9. SHELL脚本编程的条件测试
  10. linux 进程管理与调度(一)