今天 Dr. William Wallace Wettle 高端局。
A
开局不会做。搞掉 B 之后发现可以维护可能的温度的区间,秒了。
点击查看代码
#include <bits/stdc++.h>
using namespace std;struct node {int t, l, r;
}arr[100010];int _, n, m;void solve() {cin >> n >> m;for(int i = 1; i <= n; i++) {cin >> arr[i].t >> arr[i].l >> arr[i].r;}sort(arr + 1, arr + n + 1, [](node a, node b) {return a.t < b.t;});int l = m, r = m, t = 0;for(int i = 1; i <= n; i++) {int tx = arr[i].t - t;t = arr[i].t;l -= tx, r += tx;l = max(l, arr[i].l), r = min(r, arr[i].r);if(l > r) {cout << "NO" << '\n';return ;}}cout << "YES" << '\n';
}int main() {freopen("temp.in", "r", stdin);freopen("temp.out", "w", stdout);ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);for(cin >> _; _--; solve()) {}return 0;
}
B
场上第一个开的就是这个题,几分钟发现可以对每一种遗物开一个栈维护一下,秒了。
点击查看代码
#include <bits/stdc++.h>
using namespace std;int n, q, qy[100010], l, x, ans[100010];
vector<int> ch[100010], qid[100010], lmx[100010], typ[100010];void DFS(int x) {for(auto i : typ[x]) lmx[i].push_back(x);for(auto i : qid[x]) ans[i] = lmx[qy[i]].back();for(auto i : ch[x]) DFS(i);for(auto i : typ[x]) lmx[i].pop_back();
}int main() {freopen("slay.in", "r", stdin);freopen("slay.out", "w", stdout);ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);cin >> n;for(int i = 2; i <= n; i++) {cin >> x;ch[x].push_back(i);}for(int i = 1; i <= n; i++) {for(cin >> l; l--; ) {cin >> x;typ[i].push_back(x);}}cin >> q;for(int i = 1; i <= q; i++) {cin >> x >> qy[i];qid[x].push_back(i);}for(int i = 1; i <= n; i++) lmx[i].push_back(-1);DFS(1);for(int i = 1; i <= q; i++) cout << ans[i] << '\n';return 0;
}
其余
C 没想到是奇偶最短路,D 不可做(没学过斜率优化)