Perfect Judgement
首先注意到题目要求的是在时间递增的情况下,选出尽可能多的音符,使得相邻两个都能按出 Perfect。
考虑两个音符
去掉绝对值,这个条件等价于同时满足:
-
t_j - p_j \ge t_i - p_i + 2w -
t_j + p_j \ge t_i + p_i + 2w
令
于是问题转化成了:在
但注意
最终答案就是所有
::::success[AC Code]
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct Note {
int p;
long long t;
} a[N];
int n, m, w;
int dp[N];
int bit[N * 2];
vector<long long> vals;
void update(int x, int val) {
for (; x <= 2 * m; x += x & -x) bit[x] = max(bit[x], val);
}
int query(int x) {
int res = 0;
for (; x > 0; x -= x & -x) res = max(res, bit[x]);
return res;
}
int main() {
cin >> n >> m >> w;
for (int i = 1; i <= m; i++) {
cin >> a[i].p >> a[i].t;
}
for (int i = 1; i <= m; i++) {
vals.push_back(a[i].t + a[i].p);
}
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
int ans = 0;
for (int i = 1; i <= m; i++) {
int pos = lower_bound(vals.begin(), vals.end(), a[i].t + a[i].p) - vals.begin() + 1;
dp[i] = query(pos) + 1;
update(pos, dp[i]);
ans = max(ans, dp[i]);
}
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;
}
::::