Submission #642531

# Submission time Handle Problem Language Result Execution time Memory
642531 2022-09-19T19:01:16 Z elkernos Bulldozer (JOI17_bulldozer) C++17
100 / 100
774 ms 66596 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
struct T {
    int l, r, sum, ans;
    T operator+(T he) { 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<(P he) { return tie(x, y) < tie(he.x, he.y); }
    void read() { cin >> x >> y >> add; }
};
struct V {
    int dx, dy, a, b;
    bool operator<(V he) { 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 1 ms 724 KB Output is correct
5 Correct 1 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 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 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 2 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 704 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 704 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 700 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 700 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 2 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 2 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 704 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 704 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 700 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 700 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 2 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 754 ms 66476 KB Output is correct
34 Correct 743 ms 66468 KB Output is correct
35 Correct 747 ms 66420 KB Output is correct
36 Correct 736 ms 66428 KB Output is correct
37 Correct 753 ms 66444 KB Output is correct
38 Correct 742 ms 66468 KB Output is correct
39 Correct 745 ms 66448 KB Output is correct
40 Correct 746 ms 66416 KB Output is correct
41 Correct 745 ms 66404 KB Output is correct
42 Correct 750 ms 66464 KB Output is correct
43 Correct 748 ms 66416 KB Output is correct
44 Correct 740 ms 66392 KB Output is correct
45 Correct 734 ms 66512 KB Output is correct
46 Correct 741 ms 66448 KB Output is correct
47 Correct 743 ms 66456 KB Output is correct
48 Correct 747 ms 66480 KB Output is correct
49 Correct 737 ms 66416 KB Output is correct
50 Correct 748 ms 66464 KB Output is correct
51 Correct 739 ms 66544 KB Output is correct
52 Correct 735 ms 66416 KB Output is correct
53 Correct 739 ms 66448 KB Output is correct
54 Correct 742 ms 66476 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 2 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 704 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 704 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 2 ms 700 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 2 ms 700 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 2 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 754 ms 66476 KB Output is correct
34 Correct 743 ms 66468 KB Output is correct
35 Correct 747 ms 66420 KB Output is correct
36 Correct 736 ms 66428 KB Output is correct
37 Correct 753 ms 66444 KB Output is correct
38 Correct 742 ms 66468 KB Output is correct
39 Correct 745 ms 66448 KB Output is correct
40 Correct 746 ms 66416 KB Output is correct
41 Correct 745 ms 66404 KB Output is correct
42 Correct 750 ms 66464 KB Output is correct
43 Correct 748 ms 66416 KB Output is correct
44 Correct 740 ms 66392 KB Output is correct
45 Correct 734 ms 66512 KB Output is correct
46 Correct 741 ms 66448 KB Output is correct
47 Correct 743 ms 66456 KB Output is correct
48 Correct 747 ms 66480 KB Output is correct
49 Correct 737 ms 66416 KB Output is correct
50 Correct 748 ms 66464 KB Output is correct
51 Correct 739 ms 66544 KB Output is correct
52 Correct 735 ms 66416 KB Output is correct
53 Correct 739 ms 66448 KB Output is correct
54 Correct 742 ms 66476 KB Output is correct
55 Correct 759 ms 66464 KB Output is correct
56 Correct 747 ms 66416 KB Output is correct
57 Correct 755 ms 66416 KB Output is correct
58 Correct 744 ms 66400 KB Output is correct
59 Correct 738 ms 66448 KB Output is correct
60 Correct 744 ms 66448 KB Output is correct
61 Correct 774 ms 66504 KB Output is correct
62 Correct 744 ms 66456 KB Output is correct
63 Correct 754 ms 66384 KB Output is correct
64 Correct 747 ms 66472 KB Output is correct
65 Correct 742 ms 66484 KB Output is correct
66 Correct 743 ms 66500 KB Output is correct
67 Correct 732 ms 66448 KB Output is correct
68 Correct 740 ms 66492 KB Output is correct
69 Correct 738 ms 66468 KB Output is correct
70 Correct 749 ms 66412 KB Output is correct
71 Correct 742 ms 66440 KB Output is correct
72 Correct 747 ms 66428 KB Output is correct
73 Correct 743 ms 66444 KB Output is correct
74 Correct 756 ms 66412 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 1 ms 724 KB Output is correct
5 Correct 1 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 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 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 2 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 704 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 704 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 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 1 ms 212 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 324 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 2 ms 724 KB Output is correct
37 Correct 2 ms 700 KB Output is correct
38 Correct 2 ms 724 KB Output is correct
39 Correct 2 ms 700 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 2 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 754 ms 66476 KB Output is correct
49 Correct 743 ms 66468 KB Output is correct
50 Correct 747 ms 66420 KB Output is correct
51 Correct 736 ms 66428 KB Output is correct
52 Correct 753 ms 66444 KB Output is correct
53 Correct 742 ms 66468 KB Output is correct
54 Correct 745 ms 66448 KB Output is correct
55 Correct 746 ms 66416 KB Output is correct
56 Correct 745 ms 66404 KB Output is correct
57 Correct 750 ms 66464 KB Output is correct
58 Correct 748 ms 66416 KB Output is correct
59 Correct 740 ms 66392 KB Output is correct
60 Correct 734 ms 66512 KB Output is correct
61 Correct 741 ms 66448 KB Output is correct
62 Correct 743 ms 66456 KB Output is correct
63 Correct 747 ms 66480 KB Output is correct
64 Correct 737 ms 66416 KB Output is correct
65 Correct 748 ms 66464 KB Output is correct
66 Correct 739 ms 66544 KB Output is correct
67 Correct 735 ms 66416 KB Output is correct
68 Correct 739 ms 66448 KB Output is correct
69 Correct 742 ms 66476 KB Output is correct
70 Correct 759 ms 66464 KB Output is correct
71 Correct 747 ms 66416 KB Output is correct
72 Correct 755 ms 66416 KB Output is correct
73 Correct 744 ms 66400 KB Output is correct
74 Correct 738 ms 66448 KB Output is correct
75 Correct 744 ms 66448 KB Output is correct
76 Correct 774 ms 66504 KB Output is correct
77 Correct 744 ms 66456 KB Output is correct
78 Correct 754 ms 66384 KB Output is correct
79 Correct 747 ms 66472 KB Output is correct
80 Correct 742 ms 66484 KB Output is correct
81 Correct 743 ms 66500 KB Output is correct
82 Correct 732 ms 66448 KB Output is correct
83 Correct 740 ms 66492 KB Output is correct
84 Correct 738 ms 66468 KB Output is correct
85 Correct 749 ms 66412 KB Output is correct
86 Correct 742 ms 66440 KB Output is correct
87 Correct 747 ms 66428 KB Output is correct
88 Correct 743 ms 66444 KB Output is correct
89 Correct 756 ms 66412 KB Output is correct
90 Correct 752 ms 66548 KB Output is correct
91 Correct 755 ms 66524 KB Output is correct
92 Correct 743 ms 66448 KB Output is correct
93 Correct 747 ms 66428 KB Output is correct
94 Correct 742 ms 66436 KB Output is correct
95 Correct 741 ms 66496 KB Output is correct
96 Correct 738 ms 66468 KB Output is correct
97 Correct 738 ms 66408 KB Output is correct
98 Correct 732 ms 66488 KB Output is correct
99 Correct 753 ms 66436 KB Output is correct
100 Correct 620 ms 66448 KB Output is correct
101 Correct 631 ms 66416 KB Output is correct
102 Correct 605 ms 66428 KB Output is correct
103 Correct 613 ms 66508 KB Output is correct
104 Correct 613 ms 66392 KB Output is correct
105 Correct 648 ms 66436 KB Output is correct
106 Correct 657 ms 66372 KB Output is correct
107 Correct 648 ms 66452 KB Output is correct
108 Correct 645 ms 66416 KB Output is correct
109 Correct 647 ms 66416 KB Output is correct
110 Correct 702 ms 66416 KB Output is correct
111 Correct 697 ms 66448 KB Output is correct
112 Correct 706 ms 66596 KB Output is correct
113 Correct 699 ms 66448 KB Output is correct
114 Correct 706 ms 66444 KB Output is correct
115 Correct 704 ms 66360 KB Output is correct
116 Correct 703 ms 66416 KB Output is correct
117 Correct 698 ms 66544 KB Output is correct
118 Correct 713 ms 66448 KB Output is correct
119 Correct 706 ms 66416 KB Output is correct
120 Correct 0 ms 212 KB Output is correct
121 Correct 1 ms 212 KB Output is correct
122 Correct 753 ms 66484 KB Output is correct
123 Correct 750 ms 66488 KB Output is correct
124 Correct 752 ms 66484 KB Output is correct
125 Correct 750 ms 66492 KB Output is correct
126 Correct 753 ms 66484 KB Output is correct
127 Correct 751 ms 66516 KB Output is correct
128 Correct 742 ms 66448 KB Output is correct
129 Correct 733 ms 66464 KB Output is correct
130 Correct 756 ms 66488 KB Output is correct
131 Correct 749 ms 66428 KB Output is correct
132 Correct 742 ms 66468 KB Output is correct
133 Correct 732 ms 66556 KB Output is correct