Submission #642532

# Submission time Handle Problem Language Result Execution time Memory
642532 2022-09-19T19:03:28 Z elkernos Bulldozer (JOI17_bulldozer) C++17
100 / 100
821 ms 66524 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
struct T {
    int l, r, sum, ans;
    T operator+(const T &he) const { return {max(l, sum + he.l), max(r + he.sum, he.r), sum + he.sum, max({ans, he.ans, r + he.l})}; }
    void ini(int v)
    {
        sum = v;
        l = r = ans = max(0LL, v);
    }
};
struct P {
    int x, y, add;
    bool operator<(const P &he) const { return tie(x, y) < tie(he.x, he.y); }
    void read() { cin >> x >> y >> add; }
};
struct V {
    int dx, dy, a, b;
    bool operator<(const V &he) const { return make_tuple(dy * he.dx, a, b) < make_tuple(he.dy * dx, he.a, he.b); }
};

int n;
vector<T> tree;
vector<P> points;

#define m (l + r) / 2
#define lc 2 * v
#define rc 2 * v + 1
void build(int v = 1, int l = 0, int r = n - 1)
{
    if(l == r) {
        tree[v].ini(points[l].add);
    }
    else {
        build(lc, l, m), build(rc, m + 1, r);
        tree[v] = tree[lc] + tree[rc];
    }
}
void update(int where, int to, int v = 1, int l = 0, int r = n - 1)
{
    if(l == r) {
        tree[v].ini(to);
    }
    else {
        if(where <= m) {
            update(where, to, lc, l, m);
        }
        else {
            update(where, to, rc, m + 1, r);
        }
        tree[v] = tree[lc] + tree[rc];
    }
}
#undef m
#undef lc
#undef rc

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    points.resize(n);
    tree.resize(4 * n);
    vector<int> gdz(n);
    for(int i = 0; i < n; i++) {
        points[i].read();
        gdz[i] = i;
    }
    sort(points.begin(), points.end());
    vector<V> wek;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            wek.push_back({points[j].x - points[i].x, points[j].y - points[i].y, i, j});
        }
    }
    sort(wek.begin(), wek.end());
    build();
    int ans = tree[1].ans;
    int m = (int)wek.size();
    for(int i = 0; i < m; i++) {
        auto [a, b] = tie(wek[i].a, wek[i].b);
        update(gdz[a], points[b].add);
        update(gdz[b], points[a].add);
        swap(gdz[a], gdz[b]);
        if(i == m - 1 || wek[i].dy * wek[i + 1].dx != wek[i + 1].dy * wek[i].dx) {
            ans = max(ans, tree[1].ans);
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 656 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 2 ms 672 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 779 ms 66400 KB Output is correct
34 Correct 763 ms 66416 KB Output is correct
35 Correct 765 ms 66364 KB Output is correct
36 Correct 759 ms 66392 KB Output is correct
37 Correct 771 ms 66444 KB Output is correct
38 Correct 818 ms 66416 KB Output is correct
39 Correct 784 ms 66388 KB Output is correct
40 Correct 768 ms 66376 KB Output is correct
41 Correct 780 ms 66368 KB Output is correct
42 Correct 762 ms 66452 KB Output is correct
43 Correct 783 ms 66400 KB Output is correct
44 Correct 748 ms 66376 KB Output is correct
45 Correct 761 ms 66360 KB Output is correct
46 Correct 803 ms 66524 KB Output is correct
47 Correct 756 ms 66448 KB Output is correct
48 Correct 771 ms 66452 KB Output is correct
49 Correct 767 ms 66464 KB Output is correct
50 Correct 748 ms 66428 KB Output is correct
51 Correct 778 ms 66388 KB Output is correct
52 Correct 759 ms 66412 KB Output is correct
53 Correct 740 ms 66468 KB Output is correct
54 Correct 795 ms 66444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 779 ms 66400 KB Output is correct
34 Correct 763 ms 66416 KB Output is correct
35 Correct 765 ms 66364 KB Output is correct
36 Correct 759 ms 66392 KB Output is correct
37 Correct 771 ms 66444 KB Output is correct
38 Correct 818 ms 66416 KB Output is correct
39 Correct 784 ms 66388 KB Output is correct
40 Correct 768 ms 66376 KB Output is correct
41 Correct 780 ms 66368 KB Output is correct
42 Correct 762 ms 66452 KB Output is correct
43 Correct 783 ms 66400 KB Output is correct
44 Correct 748 ms 66376 KB Output is correct
45 Correct 761 ms 66360 KB Output is correct
46 Correct 803 ms 66524 KB Output is correct
47 Correct 756 ms 66448 KB Output is correct
48 Correct 771 ms 66452 KB Output is correct
49 Correct 767 ms 66464 KB Output is correct
50 Correct 748 ms 66428 KB Output is correct
51 Correct 778 ms 66388 KB Output is correct
52 Correct 759 ms 66412 KB Output is correct
53 Correct 740 ms 66468 KB Output is correct
54 Correct 795 ms 66444 KB Output is correct
55 Correct 796 ms 66420 KB Output is correct
56 Correct 762 ms 66436 KB Output is correct
57 Correct 790 ms 66448 KB Output is correct
58 Correct 771 ms 66376 KB Output is correct
59 Correct 758 ms 66388 KB Output is correct
60 Correct 775 ms 66368 KB Output is correct
61 Correct 779 ms 66480 KB Output is correct
62 Correct 776 ms 66424 KB Output is correct
63 Correct 756 ms 66448 KB Output is correct
64 Correct 775 ms 66448 KB Output is correct
65 Correct 755 ms 66408 KB Output is correct
66 Correct 794 ms 66460 KB Output is correct
67 Correct 752 ms 66400 KB Output is correct
68 Correct 761 ms 66364 KB Output is correct
69 Correct 760 ms 66400 KB Output is correct
70 Correct 804 ms 66464 KB Output is correct
71 Correct 763 ms 66356 KB Output is correct
72 Correct 780 ms 66316 KB Output is correct
73 Correct 778 ms 66420 KB Output is correct
74 Correct 771 ms 66408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 656 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 2 ms 672 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 724 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 2 ms 724 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 2 ms 724 KB Output is correct
40 Correct 2 ms 724 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 2 ms 724 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 779 ms 66400 KB Output is correct
49 Correct 763 ms 66416 KB Output is correct
50 Correct 765 ms 66364 KB Output is correct
51 Correct 759 ms 66392 KB Output is correct
52 Correct 771 ms 66444 KB Output is correct
53 Correct 818 ms 66416 KB Output is correct
54 Correct 784 ms 66388 KB Output is correct
55 Correct 768 ms 66376 KB Output is correct
56 Correct 780 ms 66368 KB Output is correct
57 Correct 762 ms 66452 KB Output is correct
58 Correct 783 ms 66400 KB Output is correct
59 Correct 748 ms 66376 KB Output is correct
60 Correct 761 ms 66360 KB Output is correct
61 Correct 803 ms 66524 KB Output is correct
62 Correct 756 ms 66448 KB Output is correct
63 Correct 771 ms 66452 KB Output is correct
64 Correct 767 ms 66464 KB Output is correct
65 Correct 748 ms 66428 KB Output is correct
66 Correct 778 ms 66388 KB Output is correct
67 Correct 759 ms 66412 KB Output is correct
68 Correct 740 ms 66468 KB Output is correct
69 Correct 795 ms 66444 KB Output is correct
70 Correct 796 ms 66420 KB Output is correct
71 Correct 762 ms 66436 KB Output is correct
72 Correct 790 ms 66448 KB Output is correct
73 Correct 771 ms 66376 KB Output is correct
74 Correct 758 ms 66388 KB Output is correct
75 Correct 775 ms 66368 KB Output is correct
76 Correct 779 ms 66480 KB Output is correct
77 Correct 776 ms 66424 KB Output is correct
78 Correct 756 ms 66448 KB Output is correct
79 Correct 775 ms 66448 KB Output is correct
80 Correct 755 ms 66408 KB Output is correct
81 Correct 794 ms 66460 KB Output is correct
82 Correct 752 ms 66400 KB Output is correct
83 Correct 761 ms 66364 KB Output is correct
84 Correct 760 ms 66400 KB Output is correct
85 Correct 804 ms 66464 KB Output is correct
86 Correct 763 ms 66356 KB Output is correct
87 Correct 780 ms 66316 KB Output is correct
88 Correct 778 ms 66420 KB Output is correct
89 Correct 771 ms 66408 KB Output is correct
90 Correct 784 ms 66452 KB Output is correct
91 Correct 769 ms 66332 KB Output is correct
92 Correct 770 ms 66452 KB Output is correct
93 Correct 764 ms 66372 KB Output is correct
94 Correct 772 ms 66400 KB Output is correct
95 Correct 794 ms 66400 KB Output is correct
96 Correct 769 ms 66444 KB Output is correct
97 Correct 759 ms 66416 KB Output is correct
98 Correct 749 ms 66428 KB Output is correct
99 Correct 755 ms 66424 KB Output is correct
100 Correct 639 ms 66448 KB Output is correct
101 Correct 642 ms 66364 KB Output is correct
102 Correct 653 ms 66448 KB Output is correct
103 Correct 621 ms 66420 KB Output is correct
104 Correct 637 ms 66428 KB Output is correct
105 Correct 681 ms 66416 KB Output is correct
106 Correct 652 ms 66364 KB Output is correct
107 Correct 662 ms 66444 KB Output is correct
108 Correct 647 ms 66360 KB Output is correct
109 Correct 657 ms 66356 KB Output is correct
110 Correct 746 ms 66416 KB Output is correct
111 Correct 716 ms 66316 KB Output is correct
112 Correct 722 ms 66448 KB Output is correct
113 Correct 717 ms 66468 KB Output is correct
114 Correct 781 ms 66416 KB Output is correct
115 Correct 732 ms 66452 KB Output is correct
116 Correct 755 ms 66416 KB Output is correct
117 Correct 759 ms 66416 KB Output is correct
118 Correct 735 ms 66400 KB Output is correct
119 Correct 702 ms 66448 KB Output is correct
120 Correct 0 ms 212 KB Output is correct
121 Correct 0 ms 212 KB Output is correct
122 Correct 761 ms 66348 KB Output is correct
123 Correct 775 ms 66412 KB Output is correct
124 Correct 785 ms 66392 KB Output is correct
125 Correct 821 ms 66448 KB Output is correct
126 Correct 799 ms 66324 KB Output is correct
127 Correct 774 ms 66460 KB Output is correct
128 Correct 792 ms 66448 KB Output is correct
129 Correct 757 ms 66356 KB Output is correct
130 Correct 769 ms 66368 KB Output is correct
131 Correct 773 ms 66448 KB Output is correct
132 Correct 766 ms 66412 KB Output is correct
133 Correct 761 ms 66428 KB Output is correct