CF2005E1 Subtangle Game (Easy Version)(绿,*2100)
只需考虑,当前第 步,是否存在先手必胜的点。
由于正着转移较为困难,所以考虑倒着转移。
定义一个先手必胜点 的覆盖范围 为左上角, 为右下角的矩形。若 步有必胜点 ,则第 步选其覆盖范围内的点就必败。
我们只需求出第 步必胜点覆盖范围的并集 ,则 的补集中才有可能产生第 步的必胜点。
最后只需判断第一步是否存在必胜点。
CF2005E2 Subtangle Game (Hard Version)(青,*2500)
上面的做法非常有前途!考虑继续优化。
发现把矩形显式地构建出来太慢了,考虑令 表示第 行第一个未被覆盖到的位置。
每次找到当前行值等于 的最后一个数,如果没被覆盖到用来更新矩形即可。
我用了二分导致带了个 。复杂度是 。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ONLINE_JUDGE
#define fi first
#define se second
#define pb push_back
#define vec vector
#define pii pair<int, int>
#define pll pair<ll, ll>
const int N = 1510;
int t;
int l, n, m;
int a[N];
int b[N][N];
vec< pii > pos[N * N];
int d[N];
void solve() {
cin >> l >> n >> m;
for (int i = l; i >= 1; i --) cin >> a[i];
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
cin >> b[i][j];
pos[b[i][j]].pb({i, j});
}
}
for (int i = 1; i <= n + 1; i ++) d[i] = 1;
for (int i = 1; i <= l; i ++) {
int cnt = 0;
for (int j = 1; j <= n; j ++) {
int p = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), make_pair(j, m)) - pos[a[i]].begin() - 1;
// cout << p << '\n';
if (p == -1) d[j - 1] = 1;
else {
pii now = pos[a[i]][p];
// cout << now.fi << " " << now.se << '\n';
if (now.fi != j) d[j - 1] = 1;
else if (now.se < d[j]) d[j - 1] = 1;
else {
cnt ++, d[j - 1] = now.se;
}
}
}
for (int j = n; j >= 1; j --) {
d[j] = max(d[j + 1], d[j]);
}
// cout << cnt << '\n';
if (i == l) {
if (!cnt) cout << "N" << '\n';
else cout << "T" << '\n';
}
}
for (int i = 1; i <= n * m; i ++) {
vec< pii >().swap(pos[i]);
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> t;
while (t --) solve();
return 0;
}