MnZn写的只过前14个点的方案 0pts 玄关求助
查看原帖
MnZn写的只过前14个点的方案 0pts 玄关求助
636977
CC__DIAMOND楼主2024/7/8 15:29
#include <bits/stdc++.h>
#define BAR cout << "*******\n";
#define fst first
#define snd second
#define INFILE(x) freopen(x, "r", stdin)
#define OUTFILE(x) freopen(x, "w", stdout)
#define mp_ make_pair
#define eb_ emplace_back
#define ep_ emplace
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ui = unsigned int;
using db = double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
constexpr int inf = 0x3f3f3f3f;
constexpr ll infl = 0x3f3f3f3f3f3f3f3fll;

namespace Solution {
    constexpr int N = 1e5 + 10;
    ll n, m, k, d;

    struct {
        ll i, val, tag;
        int lc, rc;
    } tree[2 * N];

    int tot = 0;
    int root, rn;

    void push_up(int p) {
        int lc = tree[p].lc, rc = tree[p].rc;
        ll lval = tree[lc].val, rval = tree[rc].val;
        lval -= d * (tree[rc].i - tree[lc].i);
        if (lval > rval) {
            tree[p].i = tree[lc].i;
            tree[p].val = tree[lc].val;
        } else {
            tree[p].i = tree[rc].i;
            tree[p].val = tree[rc].val;
        }
    }

    void build(int &p, int nl, int nr) {
        p = ++tot;
        if (nl == nr) {
            tree[p].i = nl;
            tree[p].val = tree[p].tag = 0;
            return;
        }
        int mid = (nl + nr) >> 1;
        build(tree[p].lc, nl, mid);
        build(tree[p].rc, mid + 1, nr);
        push_up(p);
    }

    void init() {
        tot = 0;
        build(root, 1, rn);
    }

    void upd(int p, ll val) {
        tree[p].val += val;
        tree[p].tag += val;
    }

    void push_down(int p) {
        upd(tree[p].lc, tree[p].tag);
        upd(tree[p].rc, tree[p].tag);
        tree[p].tag = 0;
    }

    void add(int l, int r, ll val, int p, int nl, int nr) {
        if (l <= nl && nr <= r) {
            upd(p, val);
            return;
        }
        int mid = (nl + nr) >> 1;
        push_down(p);
        if (l <= mid) add(l, r, val, tree[p].lc, nl, mid);
        if (r > mid) add(l, r, val, tree[p].rc, mid + 1, nr);
        push_up(p);
    }

    pll query(int l, int r, int p, int nl, int nr) {
        if (l <= nl && nr <= r) {
            return mp_(tree[p].i, tree[p].val);
        }
        push_down(p);
        int mid = (nl + nr) >> 1;
        pii lres = mp_(0, -infl), rres = mp_(0, -infl);
        if (l <= mid) lres = query(l, r, tree[p].lc, nl, mid);
        if (r > mid) rres = query(l, r, tree[p].rc, mid + 1, nr);
        ll lval = lres.snd - d * (rres.fst - lres.fst), rval = rres.snd;
        if (lval > rval) {
            return lres;
        }
        return rres;
    }

    void solve() {
        cin >> n >> m >> k >> d;
        rn = n;
        init();
        ll ans = 0;
        for (int i = 1; i <= m; ++i) {
            ll x, y, v;
            cin >> x >> y >> v;
            ll l = x - k + 1, r = x - y + 1;
            add(l, r, v, 1, 1, rn);
            pll a = query(l, r, 1, 1, rn);
            ll b = a.snd - d * (x - a.fst + 1);
            ans = max(ans, b);
            if (b > 0) add(x + 1, rn, b, 1, 1, rn);
        }
        cout << ans << '\n';
    } // namespace Solution
}

int main() {
    INFILE("run/run2.in");
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1, c;
    cin >> c >> T;
    if(c>14) return -1;
    while (T--) {
        Solution::solve();
    }
    return 0;
}

2024/7/8 15:29
加载中...