zoukankan      html  css  js  c++  java
  • noi.ac #36 模拟

    (des)
    存在 (1000 imes 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
    ", Answer[x][y]);
    	}
    	return 0;
    }
    
  • 相关阅读:
    51nod 1284:2 3 5 7的倍数 容斥原理
    POJ 2006:Litmus Test 化学公式
    POJ 2039:To and Fro
    POJ 2014:Flow Layout 模拟水题
    南阳722--数独(Dfs)
    Poj2377--Bad Cowtractors(最大生成树)
    并查集知识点总结
    Poj1861--Network(最小生成树)
    杭电2824--The Euler function(欧拉函数)
    杭电1284--钱币兑换问题(有趣)
  • 原文地址:https://www.cnblogs.com/shandongs1/p/9715027.html
Copyright © 2011-2022 走看看