題意:給你一個n*m的數陣 對于一行到另一行,若存在一列從上到下遞減,則稱之符合題意
The first line of the input contains two positive integers n and m (1?≤?n·m?≤?100?000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the following n lines contains m integers. The j-th integers in the i of these lines stands for ai,?j (1?≤?ai,?j?≤?109).The next line of the input contains an integer k (1?≤?k?≤?100?000) — the number of task that teacher gave to Alyona.The i-th of the next k lines contains two integers li and ri (1?≤?li?≤?ri?≤?n).
以上是數據范圍
a【】來存儲每一行的數
b【】來存儲每一列能到達的最上行
在用c【】來存儲每一行能到達的最上行
#include<cstdio>
using namespace std;
int a[100005],b[100005],c[100005];
int main()
{int n,m,x,i,j,r,l,k;scanf("%d%d",&n,&m);for(i=1;i<=m;i++)b[i]=1;for(i=1;i<=n;i++){c[i]=i; for(j=1;j<=m;j++){scanf("%d",&x);if(x<a[j])b[j]=i;a[j]=x; if(b[j]<c[i]) c[i]=b[j];}}scanf("%d",&k);while(k--){scanf("%d%d",&r,&l);if(c[l]<=r)printf("Yes\n");elseprintf("No\n");}return 0;
}
。
思路:由于有多次詢問所以先打表,記錄每一行所能到達的最上行即可