[Codeforces 1586] Omkar and Determination | 思维前缀和

简介: 题意给定一个n ∗ m 的方格,在这个方格中有一些点被标记为′ . ′ 说明这个点是没有障碍的,而′ X ′ 代表这个点是有障碍的,不能通过这个点,对于每个点,只能向上或者是向左走。如所说有的′ . ′ 点不能走出去,那么这样的′ . ′ 点就不是e x i t a b l e exitable问题是:给定一个矩阵里面所有的 exitable点,如果给出的矩阵能够唯一确定,就是YES,否则输出 NO所以问题就变成了给定的矩阵范围中有没有是′ . ′但是不能够 exitable的点,如果有就无法唯一确定(YES),反之就可以唯一确定(NO)数据范围太大,可以开 vector 来模拟二维数

链接


description


The problem statement looms below, filling you with determination.


Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in cells are not exitable. Note that you can exit the grid from any leftmost empty cell (cell in the first column) by going left, and from any topmost empty cell (cell in the first row) by going up.


Let’s call a grid determinable if, given only which cells are exitable, we can exactly determine which cells are filled in and which aren’t.


You are given a grid a of dimensions n×m , i. e. a grid with n rows and m columns. You need to answer q queries ( 1 ≤ q ≤ 2 ⋅ 105 )

. Each query gives two integers x 1 , x 2 ( 1 ≤ x 1 ≤ x 2 ≤ m )  and asks whether the subgrid of a consisting of the columns x 1 , x 1 + 1 , … , x 2 − 1 , x 2  is determinable.


Input


The first line contains two integers n , m ( 1 ≤ n , m ≤ 1 0 6 , n ∗ m ≤ 1 0 6 ) — the dimensions of the grid a.


n lines follow. The y-th line contains m characters, the x-th of which is ‘X’ if the cell on the intersection of the the y-th row and x-th column is filled and “.” if it is empty.


The next line contains a single integer q ( 1 ≤ q ≤ 2 ⋅ 1 0 5 )  — the number of queries.


q lines follow. Each line contains two integers x1 and x2 ( 1 ≤ x 1 ≤ x 2 ≤ m ) , representing a query asking whether the subgrid of a containing the columns x 1 , x 1 + 1 , … , x 2 − 1 , x 2  is determinable.


Output


For each query, output one line containing “YES” if the subgrid specified by the query is determinable and “NO” otherwise. The output is case insensitive (so “yEs” and “No” will also be accepted).


Example


inputCopy

4 5
..XXX
...X.
...X.
...X.
5
1 3
3 3
4 5
5 5
1 5


outputCopy

YES
YES
NO
YES
NO


Note


For each query of the example, the corresponding subgrid is displayed twice below: first in its input format, then with each cell marked as “E” if it is exitable and “N” otherwise.


For the first query:


…X EEN

… EEE

… EEE

… EEE


For the second query:


X N

. E

. E

. E

Note that you can exit the grid by going left from any leftmost cell (or up from any topmost cell); you do not need to reach the top left corner cell to exit the grid.


For the third query:


XX NN

X. NN

X. NN

X. NN

This subgrid cannot be determined only from whether each cell is exitable, because the below grid produces the above “exitability grid” as well:


XX

XX

XX

XX


For the fourth query:


X N

. E

. E

. E


For the fifth query:


…XXX EENNN

…X. EEENN

…X. EEENN

…X. EEENN

This query is simply the entire grid. It cannot be determined only from whether each cell is exitable because the below grid produces the above “exitability grid” as well:


…XXX

…XX

…XX

…XX


题意


给定一个n ∗ m 的方格,在这个方格中有一些点被标记为′ . ′ 说明这个点是没有障碍的,而′ X ′ 代表这个点是有障碍的,不能通过这个点,对于每个点,只能向上或者是向左走。如所说有的′ . ′ 点不能走出去,那么这样的′ . ′ 点就不是e x i t a b l e exitable


问题是:给定一个矩阵里面所有的 exitable点,如果给出的矩阵能够唯一确定,就是YES,否则输出 NO


所以问题就变成了给定的矩阵范围中有没有是′ . ′但是不能够 exitable的点,如果有就无法唯一确定(YES),反之就可以唯一确定(NO)

数据范围太大,可以开 vector 来模拟二维数组,也可以使用一维数组转化


vector<int> vet[maxn];
vector<int> vis[maxn];
int sum[maxn];
int n,m;
int main() {
  cin >> n >> m;
  getchar();
  for(int i=1;i<=n;i++) vis[i].clear(),vet[i].clear(),vet[i].push_back(0);
  for(int i=0;i<=m;i++) vet[0].push_back(0);
  for(int i=1;i<=n;i++) {
    for(int j=1;j<=m;j++) {
      char c = getchar();
      int x = 0;
      if(c == 'X') x = 1;
      vet[i].push_back(x);
    }
    getchar();
    // getchar();
  }
  for(int i=1;i<=n;i++) {
    vis[i].push_back(0);
    for(int j=1;j<=m;j++) {
      if(vet[i-1][j] && vet[i][j-1]) vis[i].push_back(1);/// ???
      else vis[i].push_back(0);
    }
  }
  for(int j=1;j<=m;j++) {
    for(int i=1;i<=n;i++) {
      sum[j] += vis[i][j];
    }
    sum[j] += sum[j-1];
    // cout << sum[j] << ' ';
  }
  // puts("\n input");
  int t;
  cin >> t;
  while(t --) {
    int l = read,r = read;
    if(sum[r] - sum[l]) puts("NO");
    else puts("YES");
  }
  return 0;
}
/**
**/


目录
相关文章
|
人工智能
[Codeforces 1589D] Guess the Permutation | 交互 思维 二分
题意 多组输入:{ 每组给出一个n,有一个长度为n的数列,在开始的时候a i = i ,有三个数i , j , k 数列反转了 [i,j−1] [j,k] 要求出这三个数,可以对系统进行询问 [ l , r ] 区间内 逆序对 的个数,会返回这个值 }
132 0
|
人工智能
Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)
A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard outp...
1296 0
|
5G
[NCPC2021] Antenna Analysis | 思维递推
题目描述 Åke has heard that there may be some suspicious 5G radiation in his city. To test this, he uses the antenna on his roof to measure the 5G level each day. However, he does not know how he should analyze the data.
268 0
|
人工智能
Codeforces1491——C.Pekora and Trampoline(差分思维+树状数组)
Codeforces1491——C.Pekora and Trampoline(差分思维+树状数组)
118 0
Codeforces1491——C.Pekora and Trampoline(差分思维+树状数组)
UCF 2021 Practice F.Balanced Strings (思维 组合数学)
UCF 2021 Practice F.Balanced Strings (思维 组合数学)
112 0
AtCoder Beginner Contest 203 Pond(二分+二维前缀和)
大体思路: 二分,将原矩阵根据二分的值变成01矩阵,如果元素值> val 就变为1,否则0 对于k * k 的矩阵,统计区域内元素之和,如果 sum < ⌊k2 / 2⌋ + 1,意味着当前k * k矩阵的中位数小于x,而x是我们的答案(最小中位数), ①sum < ⌊k2 / 2⌋ + 1 情况下x取得太大,r = mid ②反之,x还可能取更小的,l = mid 但是需要注意下l的初始值,当取0 or 1的时候是会wa掉的:
261 0
AtCoder Beginner Contest 203 Pond(二分+二维前缀和)
|
人工智能 网络架构
Codeforces 839D Winter is here【数学:容斥原理】
D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard out...
1077 0
Codeforces 789A Anastasia and pebbles(数学,思维题)
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard o...
1192 0

热门文章

最新文章