Submission #110068

# Submission time Handle Problem Language Result Execution time Memory
110068 2019-05-09T07:37:16 Z popovicirobert Bulldozer (JOI17_bulldozer) C++14
75 / 100
808 ms 33476 KB
#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 time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 733 ms 33344 KB Output is correct
34 Correct 756 ms 33360 KB Output is correct
35 Correct 767 ms 33348 KB Output is correct
36 Correct 760 ms 33360 KB Output is correct
37 Correct 762 ms 33360 KB Output is correct
38 Correct 754 ms 33344 KB Output is correct
39 Correct 751 ms 33360 KB Output is correct
40 Correct 759 ms 33344 KB Output is correct
41 Correct 737 ms 33360 KB Output is correct
42 Correct 723 ms 33348 KB Output is correct
43 Correct 721 ms 33360 KB Output is correct
44 Correct 747 ms 33360 KB Output is correct
45 Correct 749 ms 33344 KB Output is correct
46 Correct 750 ms 33356 KB Output is correct
47 Correct 746 ms 33360 KB Output is correct
48 Correct 724 ms 33312 KB Output is correct
49 Correct 753 ms 33340 KB Output is correct
50 Correct 730 ms 33360 KB Output is correct
51 Correct 736 ms 33396 KB Output is correct
52 Correct 719 ms 33344 KB Output is correct
53 Correct 720 ms 33372 KB Output is correct
54 Correct 724 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 733 ms 33344 KB Output is correct
34 Correct 756 ms 33360 KB Output is correct
35 Correct 767 ms 33348 KB Output is correct
36 Correct 760 ms 33360 KB Output is correct
37 Correct 762 ms 33360 KB Output is correct
38 Correct 754 ms 33344 KB Output is correct
39 Correct 751 ms 33360 KB Output is correct
40 Correct 759 ms 33344 KB Output is correct
41 Correct 737 ms 33360 KB Output is correct
42 Correct 723 ms 33348 KB Output is correct
43 Correct 721 ms 33360 KB Output is correct
44 Correct 747 ms 33360 KB Output is correct
45 Correct 749 ms 33344 KB Output is correct
46 Correct 750 ms 33356 KB Output is correct
47 Correct 746 ms 33360 KB Output is correct
48 Correct 724 ms 33312 KB Output is correct
49 Correct 753 ms 33340 KB Output is correct
50 Correct 730 ms 33360 KB Output is correct
51 Correct 736 ms 33396 KB Output is correct
52 Correct 719 ms 33344 KB Output is correct
53 Correct 720 ms 33372 KB Output is correct
54 Correct 724 ms 33344 KB Output is correct
55 Correct 729 ms 33476 KB Output is correct
56 Correct 722 ms 33360 KB Output is correct
57 Correct 725 ms 33360 KB Output is correct
58 Correct 720 ms 33348 KB Output is correct
59 Correct 724 ms 33360 KB Output is correct
60 Correct 729 ms 33360 KB Output is correct
61 Correct 733 ms 33344 KB Output is correct
62 Correct 733 ms 33472 KB Output is correct
63 Correct 771 ms 33344 KB Output is correct
64 Correct 754 ms 33344 KB Output is correct
65 Correct 762 ms 33364 KB Output is correct
66 Correct 745 ms 33364 KB Output is correct
67 Correct 808 ms 33360 KB Output is correct
68 Correct 743 ms 33280 KB Output is correct
69 Correct 733 ms 33292 KB Output is correct
70 Correct 740 ms 33336 KB Output is correct
71 Correct 730 ms 33388 KB Output is correct
72 Correct 726 ms 33368 KB Output is correct
73 Correct 722 ms 33360 KB Output is correct
74 Correct 731 ms 33360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -