原题
E. Reverse the Rivers
思路
从上往下一定是越来越大,因此分成两个去看,即对于大于和小于分开去思考
代码
#include <bits/stdc++.h>
using namespace std;int main()
{int n, k, q;cin >> n >> k >> q;vector<vector<int>> a(k, vector<int> (n));for (int i = 0; i < n; i ++ ){for (int j = 0; j < k; j ++ ){cin >> a[j][i];if (i > 0)a[j][i] |= a[j][i - 1];}}while (q -- ){int m;cin >> m;int low = 0, high = n;while (m -- ){int r, x;char c;cin >> r >> c >> x;r --;if (c == '>'){low = max(low, int(upper_bound(a[r].begin(), a[r].end(), x) - a[r].begin()));}else{high = min(high, int(lower_bound(a[r].begin(), a[r].end(), x) - a[r].begin()));}}cout << (low < high ? low + 1: -1) << endl;}
}