题解:P13649 [NOISG 2016] Panda Ski
思路
实际上只需要一个代码。
首先我们注意力惊人然后可以发现这个题数据非常阴,
对于满足
这就是一个 DAG DP,因为显然
然后对于前一个条件
(笔者这里采用了单调栈做法,刚需
请读者先理解以上部分。
接着对于满足
我们可以想到,在
可以考虑在以
不难发现对于满足
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll (k<<1)
#define rr (k<<1|1)
#define eps 60000
int n, h, ans;
struct tree {
int l, r;
vector<pair<int, int>> d;
} t[1500005];
struct node {
int x, y, s, e;
} a[300005];
inline bool cmp(node x, node y) {
if (x.y == y.y) return x.x < y.x;
return x.y < y.y;
}
void build(int k, int l, int r) {
t[k].l = l, t[k].r = r;
if (l == r) {
return ;
}
int mid = (l + r) >> 1;
build(ll, l, mid);
build(rr, mid + 1, r);
return ;
}
void update(int k, int p, int c, int g) {
if (t[k].l > p || t[k].r < p) return ;
while (!t[k].d.empty() && t[k].d.back().second < g) t[k].d.pop_back();
t[k].d.emplace_back(c, g);
if (t[k].l == t[k].r) return ;
update(ll, p, c, g);
update(rr, p, c, g);
}
int query(int k, int l, int r, int c) {
if (l <= 0) l = 1;
if (r >= 200000) r = 200000;
if (t[k].l > r || t[k].r < l) return 0;
if (t[k].l >= l && t[k].r <= r) {
auto it = lower_bound(t[k].d.begin(), t[k].d.end(), make_pair(c, 0ll));
if (it == t[k].d.end()) return 0;
return it->second;
}
return max(query(ll, l, r, c), query(rr, l, r, c));
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> h;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].s >> a[i].e;
a[i].x += eps;
}
sort(a + 1, a + n + 1, cmp);
build(1, 1, 200000);
for (int i = 1; i <= n; i++) {
if (a[i].y != a[i - 1].y) {
int now = i;
while (a[now + 1].y == a[now].y) now++;
int sum = a[i].s, lst = i, maxa = 0;
for (int j = i + 1; j <= now; j++) {
if (a[j].x - a[j - 1].x <= a[i].e) {
sum += a[j].s;
} else {
maxa = query(1, a[lst].x - a[i].e, a[j - 1].x + a[i].e, a[i].y - a[i].e);
ans = max(ans, maxa + sum);
for (int o = lst; o <= j - 1; o++) update(1, a[o].x, a[o].y, sum + maxa);
sum = a[j].s, lst = j;
}
}
maxa = query(1, a[lst].x - a[i].e, a[now].x + a[i].e, a[i].y - a[i].e);
ans = max(ans, maxa + sum);
for (int o = lst; o <= now; o++) update(1, a[o].x, a[o].y, sum + maxa);
} else continue;
}
cout << ans;
return 0;
}