답안 #110072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110072 2019-05-09T08:50:37 Z popovicirobert Bulldozer (JOI17_bulldozer) C++14
100 / 100
824 ms 33496 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) {
            return make_pair(id1, id2) < make_pair(other.id1, other.id2);
        }
        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;
}
# 결과 실행 시간 메모리 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 4 ms 556 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 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 356 KB Output is correct
# 결과 실행 시간 메모리 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 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 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 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 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 512 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 484 KB Output is correct
28 Correct 3 ms 560 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
# 결과 실행 시간 메모리 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 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 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 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 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 512 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 484 KB Output is correct
28 Correct 3 ms 560 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 716 ms 33296 KB Output is correct
34 Correct 703 ms 33360 KB Output is correct
35 Correct 728 ms 33344 KB Output is correct
36 Correct 764 ms 33344 KB Output is correct
37 Correct 715 ms 33380 KB Output is correct
38 Correct 713 ms 33368 KB Output is correct
39 Correct 718 ms 33360 KB Output is correct
40 Correct 743 ms 33344 KB Output is correct
41 Correct 733 ms 33400 KB Output is correct
42 Correct 730 ms 33276 KB Output is correct
43 Correct 731 ms 33300 KB Output is correct
44 Correct 706 ms 33420 KB Output is correct
45 Correct 716 ms 33360 KB Output is correct
46 Correct 706 ms 33312 KB Output is correct
47 Correct 718 ms 33344 KB Output is correct
48 Correct 744 ms 33344 KB Output is correct
49 Correct 710 ms 33328 KB Output is correct
50 Correct 704 ms 33316 KB Output is correct
51 Correct 714 ms 33316 KB Output is correct
52 Correct 725 ms 33372 KB Output is correct
53 Correct 704 ms 33336 KB Output is correct
54 Correct 715 ms 33372 KB Output is correct
# 결과 실행 시간 메모리 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 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 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 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 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 512 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 484 KB Output is correct
28 Correct 3 ms 560 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 716 ms 33296 KB Output is correct
34 Correct 703 ms 33360 KB Output is correct
35 Correct 728 ms 33344 KB Output is correct
36 Correct 764 ms 33344 KB Output is correct
37 Correct 715 ms 33380 KB Output is correct
38 Correct 713 ms 33368 KB Output is correct
39 Correct 718 ms 33360 KB Output is correct
40 Correct 743 ms 33344 KB Output is correct
41 Correct 733 ms 33400 KB Output is correct
42 Correct 730 ms 33276 KB Output is correct
43 Correct 731 ms 33300 KB Output is correct
44 Correct 706 ms 33420 KB Output is correct
45 Correct 716 ms 33360 KB Output is correct
46 Correct 706 ms 33312 KB Output is correct
47 Correct 718 ms 33344 KB Output is correct
48 Correct 744 ms 33344 KB Output is correct
49 Correct 710 ms 33328 KB Output is correct
50 Correct 704 ms 33316 KB Output is correct
51 Correct 714 ms 33316 KB Output is correct
52 Correct 725 ms 33372 KB Output is correct
53 Correct 704 ms 33336 KB Output is correct
54 Correct 715 ms 33372 KB Output is correct
55 Correct 705 ms 33360 KB Output is correct
56 Correct 708 ms 33300 KB Output is correct
57 Correct 712 ms 33332 KB Output is correct
58 Correct 734 ms 33332 KB Output is correct
59 Correct 714 ms 33360 KB Output is correct
60 Correct 732 ms 33348 KB Output is correct
61 Correct 716 ms 33340 KB Output is correct
62 Correct 710 ms 33344 KB Output is correct
63 Correct 710 ms 33344 KB Output is correct
64 Correct 704 ms 33364 KB Output is correct
65 Correct 715 ms 33344 KB Output is correct
66 Correct 709 ms 33348 KB Output is correct
67 Correct 715 ms 33360 KB Output is correct
68 Correct 716 ms 33332 KB Output is correct
69 Correct 707 ms 33360 KB Output is correct
70 Correct 713 ms 33372 KB Output is correct
71 Correct 731 ms 33360 KB Output is correct
72 Correct 739 ms 33360 KB Output is correct
73 Correct 719 ms 33344 KB Output is correct
74 Correct 728 ms 33472 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 556 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 256 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 356 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 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 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 484 KB Output is correct
43 Correct 3 ms 560 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 716 ms 33296 KB Output is correct
49 Correct 703 ms 33360 KB Output is correct
50 Correct 728 ms 33344 KB Output is correct
51 Correct 764 ms 33344 KB Output is correct
52 Correct 715 ms 33380 KB Output is correct
53 Correct 713 ms 33368 KB Output is correct
54 Correct 718 ms 33360 KB Output is correct
55 Correct 743 ms 33344 KB Output is correct
56 Correct 733 ms 33400 KB Output is correct
57 Correct 730 ms 33276 KB Output is correct
58 Correct 731 ms 33300 KB Output is correct
59 Correct 706 ms 33420 KB Output is correct
60 Correct 716 ms 33360 KB Output is correct
61 Correct 706 ms 33312 KB Output is correct
62 Correct 718 ms 33344 KB Output is correct
63 Correct 744 ms 33344 KB Output is correct
64 Correct 710 ms 33328 KB Output is correct
65 Correct 704 ms 33316 KB Output is correct
66 Correct 714 ms 33316 KB Output is correct
67 Correct 725 ms 33372 KB Output is correct
68 Correct 704 ms 33336 KB Output is correct
69 Correct 715 ms 33372 KB Output is correct
70 Correct 705 ms 33360 KB Output is correct
71 Correct 708 ms 33300 KB Output is correct
72 Correct 712 ms 33332 KB Output is correct
73 Correct 734 ms 33332 KB Output is correct
74 Correct 714 ms 33360 KB Output is correct
75 Correct 732 ms 33348 KB Output is correct
76 Correct 716 ms 33340 KB Output is correct
77 Correct 710 ms 33344 KB Output is correct
78 Correct 710 ms 33344 KB Output is correct
79 Correct 704 ms 33364 KB Output is correct
80 Correct 715 ms 33344 KB Output is correct
81 Correct 709 ms 33348 KB Output is correct
82 Correct 715 ms 33360 KB Output is correct
83 Correct 716 ms 33332 KB Output is correct
84 Correct 707 ms 33360 KB Output is correct
85 Correct 713 ms 33372 KB Output is correct
86 Correct 731 ms 33360 KB Output is correct
87 Correct 739 ms 33360 KB Output is correct
88 Correct 719 ms 33344 KB Output is correct
89 Correct 728 ms 33472 KB Output is correct
90 Correct 731 ms 33360 KB Output is correct
91 Correct 703 ms 33360 KB Output is correct
92 Correct 716 ms 33320 KB Output is correct
93 Correct 726 ms 33344 KB Output is correct
94 Correct 720 ms 33360 KB Output is correct
95 Correct 705 ms 33360 KB Output is correct
96 Correct 726 ms 33360 KB Output is correct
97 Correct 763 ms 33344 KB Output is correct
98 Correct 718 ms 33344 KB Output is correct
99 Correct 731 ms 33332 KB Output is correct
100 Correct 325 ms 16968 KB Output is correct
101 Correct 335 ms 16960 KB Output is correct
102 Correct 324 ms 16904 KB Output is correct
103 Correct 320 ms 16936 KB Output is correct
104 Correct 323 ms 16948 KB Output is correct
105 Correct 449 ms 33472 KB Output is correct
106 Correct 461 ms 33284 KB Output is correct
107 Correct 458 ms 33344 KB Output is correct
108 Correct 454 ms 33424 KB Output is correct
109 Correct 464 ms 33348 KB Output is correct
110 Correct 674 ms 33412 KB Output is correct
111 Correct 664 ms 33360 KB Output is correct
112 Correct 661 ms 33360 KB Output is correct
113 Correct 665 ms 33320 KB Output is correct
114 Correct 670 ms 33360 KB Output is correct
115 Correct 685 ms 33360 KB Output is correct
116 Correct 673 ms 33384 KB Output is correct
117 Correct 651 ms 33360 KB Output is correct
118 Correct 648 ms 33348 KB Output is correct
119 Correct 639 ms 33296 KB Output is correct
120 Correct 2 ms 384 KB Output is correct
121 Correct 2 ms 384 KB Output is correct
122 Correct 714 ms 33360 KB Output is correct
123 Correct 711 ms 33496 KB Output is correct
124 Correct 745 ms 33340 KB Output is correct
125 Correct 786 ms 33344 KB Output is correct
126 Correct 824 ms 33360 KB Output is correct
127 Correct 705 ms 33344 KB Output is correct
128 Correct 719 ms 33344 KB Output is correct
129 Correct 708 ms 33360 KB Output is correct
130 Correct 709 ms 33344 KB Output is correct
131 Correct 705 ms 33360 KB Output is correct
132 Correct 708 ms 33360 KB Output is correct
133 Correct 715 ms 33364 KB Output is correct