题目链接:http://codeforces.com/problemset/problem/777/C
才开始做的时候,一直因为不能开10^5 的数组,而没有思路,看了网上一些大牛的思路,真是受教了,自己做了一下,留做纪念。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX_N = 100000 + 10;
const int INF = 1e6;
int col[MAX_N];
int temp[MAX_N];
int ans[MAX_N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
while (cin >> n >> m) {
fill(temp, temp + MAX_N, INF);
memset(col, 0, sizeof col);
memset(ans, 0, sizeof ans);
for (int i = 1; i <= n; ++i) {
int id = INF;
for (int j = 0; j < m; ++j) {
int v;
cin >> v;
if (v < temp[j]) col[j] = i;
temp[j] = v;
id = min(id, col[j]);
}
ans[i] = id;
}
int k;
cin >> k;
while (k--) {
int l, r;
cin >> l >> r;
if (ans[r] > l) cout << "No" << endl;
else cout << "Yes" << endl;
}
}
return 0;
}
网友评论