zoukankan      html  css  js  c++  java
  • Codeforces-777C. Alyona and Spreadsheet

    传送门

    n*m维矩阵,Q次询问,查询行数为[l,r]的矩阵内是否有某一列满足自上而下数据非减

    其中1 ≤ n·m ≤ 100 000

    对于某一行的任一列,记录其对应能满足数据非减的最小行(B[i][j]),进而得出每一行能满足条件的最小行(bst[i]),查询时判断bst[r]与l的关系即可

    显然当aij>a(i-1)j,B[i][j]=B[i-1][j], 否则B[i][j]=i;

    在每一行结束时记录下bst[i],就可以重复利用数组B了,只使用一维数组了

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #define INF 0x3f3f3f3f
     6 #define MOD 1000000007
     7 using namespace std;
     8 typedef long long LL;
     9 
    10 int N, M, Q;
    11 const int maxn = 1e5 + 10;
    12 int A[3][maxn];
    13 int B[maxn];
    14 int bst[maxn];
    15 
    16 int main() {
    17     for (int j = 1; j <= M; j++) {
    18         B[j] = 1;
    19     }
    20     scanf("%d%d", &N, &M);
    21     for (int i = 1; i <= N; i++) {
    22         int t = i & 1;
    23         for (int j = 1; j <= M; j++) {
    24             scanf("%d", &A[t][j]);
    25         }
    26         for (int j = 1; j <= M; j++) {
    27             B[j] = A[t][j] >= A[!t][j] ? B[j] : i;
    28         }
    29         bst[i] = N + 1;
    30         for (int j = 1; j <= M; j++) {
    31             bst[i] = min(bst[i], B[j]);
    32         }
    33     }
    34     scanf("%d", &Q);
    35     int dn, up;
    36     while (Q--) {
    37         scanf("%d%d", &dn, &up);
    38         if (bst[up] <= dn) {
    39             puts("Yes");
    40         } else {
    41             puts("No");
    42         }
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    七种数据类型
    js字符串解析成数字
    html节点操作与事件
    form表单的默认提交行为
    CSS中的各种width(宽度)
    Javascript读写CSS属性
    ECMAScript6新特性之Reflect
    ECMAScript6新特性之String API
    ECMAScript6新特性之Array API
    判断Javascript对象是否为空
  • 原文地址:https://www.cnblogs.com/xFANx/p/8413252.html
Copyright © 2011-2022 走看看