版本比较
Perfect Judgement
正文
增加 131 行删除 2 行
12123460 行未改动6566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199## 思路
首先注意到题目要求的是在时间递增的情况下,选出尽可能多的音符,使得相邻两个都能按出 Perfect。
考虑两个音符 $i$ 和 $j$($i < j$),能连续按出的条件是什么?手指要从 $p_i$ 移动到 $p_j$,花费 $|p_i - p_j|$ 毫秒,而两个音符的可击打区间分别是 $[t_i - w, t_i + w]$ 和 $[t_j - w, t_j + w]$。最紧的情况是尽量晚按 $i$、尽量早按 $j$,所以需要 $(t_j - w) - (t_i + w) \ge |p_i - p_j|$,即 $t_j - t_i \ge |p_i - p_j| + 2w$。
60 行未改动 cout << ans << endl; return 0;}::::
::::success[AC]
```cpp#include<bits/stdc++.h>typedef long long ll;using namespace std;
const int MAXN = 1e5 + 10;const int ST_SIZE = 4 * MAXN; const ll INF = 1e18;
struct N { int p; ll t, L, R;} nd[MAXN];
struct ST { int l, r; int mc; ll mt; } tr[ST_SIZE];
inline void pu(int u) { tr[u].mc = max(tr[u<<1].mc, tr[u<<1|1].mc);}
void bd(int u, int l, int r) { tr[u].l = l; tr[u].r = r; tr[u].mc = 0; tr[u].mt = -INF; if (l == r) return; int m = (l + r) >> 1; if (u > ST_SIZE / 2) return; bd(u<<1, l, m); bd(u<<1|1, m+1, r);}
void up(int pos, int c, ll t) { int u = 1; while (tr[u].l != tr[u].r) { int m = (tr[u].l + tr[u].r) >> 1; if (pos <= m) u = u << 1; else u = u << 1 | 1; } if (c > tr[u].mc || (c == tr[u].mc && t < tr[u].mt)) { tr[u].mc = c; tr[u].mt = t; } u >>= 1; while (u >= 1) { pu(u); u >>= 1; }}
int qy(int pos, ll L) { int res = 0; queue<int> q; q.push(1); while (!q.empty()) { int u = q.front(); q.pop(); if (tr[u].l == tr[u].r) { ll cost = abs(pos - tr[u].l); if (tr[u].mt != -INF && tr[u].mt + cost <= L) { res = max(res, tr[u].mc); } continue; } q.push(u<<1); q.push(u<<1|1); } return res;}
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, m, w; if (!(cin >> n >> m >> w)) { cout << "0\n"; return 0; }
for (int i = 1; i <= m; i++) { cin >> nd[i].p >> nd[i].t; nd[i].L = max(0LL, nd[i].t - w); nd[i].R = nd[i].t + w; }
n = min(n, MAXN - 10); bd(1, 1, n); int ans = 0;
for (int i = 1; i <= m; i++) { int p = nd[i].p; if (p < 1 || p > n) continue; ll L = nd[i].L; int mx = qy(p, L); int cur = mx + 1; ans = max(ans, cur); up(p, cur, L); }
cout << ans << '\n'; return 0;}::::