Submission #110068

#TimeUsernameProblemLanguageResultExecution timeMemory
110068popovicirobertBulldozer (JOI17_bulldozer)C++14
75 / 100
808 ms33476 KiB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const ll INF = 1e18;

struct SegTree {

    struct Node {
        ll pref, suff;
        ll best, sum;
    };

    vector <Node> aint;
    int n;

    inline void init(int _n) {
        n = _n;
        aint.resize(4 * n + 1, {-INF, -INF, -INF, -INF});
    }

    inline void refresh(int nod) {
        aint[nod].sum = aint[2 * nod].sum + aint[2 * nod + 1].sum;
        aint[nod].pref = max(aint[2 * nod].pref, aint[2 * nod].sum + aint[2 * nod + 1].pref);
        aint[nod].suff = max(aint[2 * nod + 1].suff, aint[2 * nod + 1].sum + aint[2 * nod].suff);
        aint[nod].best = max(max(aint[2 * nod].best, aint[2 * nod + 1].best), aint[2 * nod].suff + aint[2 * nod + 1].pref);
    }

    void update(int nod, int left, int right, int pos, int val) {
        if(left == right) {
            aint[nod] = {val, val, val, val};
        }
        else {
            int mid = (left + right) / 2;
            if(pos <= mid) update(2 * nod, left, mid, pos, val);
            else update(2 * nod + 1, mid + 1, right, pos, val);
            refresh(nod);
        }
    }

};

struct Point {
    int x, y;
    int val;
    bool operator <(const Point &other) const {
        if(x == other.x)
            return y < other.y;
        return x < other.x;
    }
};

struct Slope {
    int a, b;
    int id1, id2;
    bool operator <(const Slope &other) const {
        ll s1 = 1LL * a * other.b, s2 = 1LL * other.a * b;
        if(s1 == s2) {
            if(a == other.a) return b < other.b;
            return a < other.a;
        }
        return s1 < s2;
    }
};

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    vector <Point> pts(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> pts[i].x >> pts[i].y >> pts[i].val;
    }

    sort(next(pts.begin()), pts.end());

    vector <Slope> slp;
    for(i = 1; i <= n; i++) {
        for(j = i + 1; j <= n; j++) {
            if(pts[i].x != pts[j].x) {
                slp.push_back({pts[j].y - pts[i].y, pts[j].x - pts[i].x, i, j});
            }
        }
    }

    sort(slp.begin(), slp.end());

    SegTree st; st.init(n);
    vector <int> pos(n + 1);

    for(i = 1; i <= n; i++) {
        st.update(1, 1, n, i, pts[i].val);
        pos[i] = i;
    }

    ll ans = max(0LL, st.aint[1].best);

    int sz = slp.size();
    i = 0;

    while(i < sz) {
        int j = i;
        while(j < sz && 1LL * slp[i].a * slp[j].b == 1LL * slp[j].a * slp[i].b) {
            st.update(1, 1, n, pos[slp[j].id2], pts[slp[j].id1].val);
            st.update(1, 1, n, pos[slp[j].id1], pts[slp[j].id2].val);
            swap(pos[slp[j].id1], pos[slp[j].id2]);
            j++;
        }
        ans = max(ans, st.aint[1].best);
        i = j;
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...