Submission #68457766


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define _f(i, l, r) for (int i = l; i <= r; ++i)
#define _r(i, r, l) for (int i = r; i >= l; --i)
#define FASTIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
const int N = 1e5+5, M = 1005, inf = 0xc0c0c0c0c0c0c0c0;
int n;
struct item {
    int t, x, y, a, q, id;
    inline friend bool operator < (const item& a, const item& b) {
        return a.t-a.x-a.y < b.t-b.x-b.y;
    }
    inline friend bool operator <= (const item& a, const item& b) {
        return a.t-a.x-a.y <= b.t-b.x-b.y;
    }
} a[N], b[N];
int p[N], t;
int f[N];
struct SegmentTree {
    int c[N];
    int st[N*20], tp;
    SegmentTree() { memset(c, 0xc0, sizeof(c)); }
    inline void clear() { for (; tp > 0; tp--) c[st[tp]] = inf; }
    inline void upd(int x, int v) {
        for (; x <= t; x += x & -x) st[++tp] = x, c[x] = max(c[x], v); 
    }
    inline int qry(int x) {
        int mx = inf;
        for (; x; x -= x & -x) mx = max(mx, c[x]);
        return mx;
    }
} sgt;
void cdq(int l, int r) {
    if (l == r) return ;
    int mid = (l+r)>>1;
    cdq(l, mid);
    copy(a+mid+1, a+r+1, b+mid+1);
    stable_sort(b+mid+1, b+r+1);
    int lt = l, rt = mid+1;
    sgt.clear();
    while (lt <= mid || rt <= r) {
        if (rt > r || (lt <= mid && a[lt] <= b[rt])) sgt.upd(a[lt].q, f[a[lt].id]), lt++;
        else f[b[rt].id] = max(f[b[rt].id], sgt.qry(b[rt].q)+b[rt].a), rt++;
    }
    cdq(mid+1, r);
    merge(a+l, a+mid+1, a+mid+1, a+r+1, b+l);
    copy(b+l, b+r+1, a+l);
}
signed main() {
	FASTIO;
    cin >> n;
    _f(i, 1, n) cin >> a[i].t >> a[i].x >> a[i].y >> a[i].a;
    a[++n] = {0,0,0,0,0,0};
    _f(i, 1, n) a[i].id = i, p[++t] = a[i].y;
    stable_sort(p+1, p+t+1);
    t = unique(p+1, p+t+1)-p-1;
    _f(i, 1, n) a[i].q = lower_bound(p+1, p+t+1, a[i].y)-p;
    stable_sort(a+1, a+n+1, [](const item& a, const item& b) { return a.t+a.x-a.y == b.t+b.x-b.y ? a.t < b.t : a.t+a.x-a.y < b.t+b.x-b.y; });
    memset(f, 0xc0, sizeof(f));
    f[n] = 0;
    cdq(1, n);
    cout << *max_element(f+1, f+n+1) << '\n';
	return 0;
}

Submission Info

Submission Time
Task Ex - Snuke Panic (2D)
User marking_ray
Language C++ 20 (gcc 12.2)
Score 600
Code Size 2152 Byte
Status AC
Exec Time 146 ms
Memory 19984 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
min.txt AC 2 ms 5056 KiB
random_01.txt AC 145 ms 19612 KiB
random_02.txt AC 23 ms 7716 KiB
random_03.txt AC 145 ms 19744 KiB
random_04.txt AC 70 ms 12448 KiB
random_05.txt AC 146 ms 19692 KiB
random_06.txt AC 107 ms 16104 KiB
random_07.txt AC 146 ms 19828 KiB
random_08.txt AC 57 ms 11300 KiB
random_09.txt AC 145 ms 19624 KiB
random_10.txt AC 6 ms 5648 KiB
random_11.txt AC 146 ms 19556 KiB
random_12.txt AC 65 ms 12020 KiB
random_13.txt AC 145 ms 19684 KiB
random_14.txt AC 40 ms 9584 KiB
random_15.txt AC 145 ms 19612 KiB
random_16.txt AC 32 ms 8604 KiB
random_17.txt AC 145 ms 19688 KiB
random_18.txt AC 15 ms 6900 KiB
random_19.txt AC 146 ms 19676 KiB
random_20.txt AC 26 ms 7936 KiB
random_21.txt AC 115 ms 17976 KiB
random_22.txt AC 53 ms 11552 KiB
random_23.txt AC 114 ms 17848 KiB
random_24.txt AC 4 ms 5576 KiB
random_25.txt AC 115 ms 17848 KiB
random_26.txt AC 70 ms 13124 KiB
random_27.txt AC 116 ms 17900 KiB
random_28.txt AC 4 ms 5380 KiB
random_29.txt AC 115 ms 17704 KiB
random_30.txt AC 52 ms 11192 KiB
random_31.txt AC 7 ms 6420 KiB
random_32.txt AC 7 ms 6308 KiB
random_33.txt AC 71 ms 19984 KiB
random_34.txt AC 31 ms 12188 KiB
sample_01.txt AC 1 ms 5004 KiB
sample_02.txt AC 1 ms 5064 KiB
sample_03.txt AC 2 ms 4996 KiB