답안 #521405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521405 2022-02-02T04:37:25 Z tengiz05 Bulldozer (JOI17_bulldozer) C++17
100 / 100
1034 ms 33496 KB
#include <bits/stdc++.h>

using i64 = long long;

struct Info {
    i64 pr, sf;
    i64 sum;
    i64 ans;
    Info(i64 x = 0) : pr(std::max(0LL, x)), sf(std::max(0LL, x)), sum(x), ans(std::max(0LL, x)) {}
};
Info operator+(const Info &a, const Info &b) {
    Info res;
    res.pr = std::max(a.pr, a.sum + b.pr);
    res.sf = std::max(b.sf, a.sf + b.sum);
    res.sum = a.sum + b.sum;
    res.ans = std::max({a.ans, b.ans, a.sf + b.pr});
    return res;
}
template<class Info,
    class Merge = std::plus<Info>>
struct SegmentTree {
    const int n;
    const Merge merge;
    std::vector<Info> info;
    SegmentTree(int n) : n(n), merge(Merge()), info(4 << std::__lg(n)) {}
    SegmentTree(std::vector<Info> init) : SegmentTree(init.size()) {
        std::function<void(int, int, int)> build = [&](int p, int l, int r) {
            if (r - l == 1) {
                info[p] = init[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m, r);
            pull(p);
        };
        build(1, 0, n);
    }
    void pull(int p) {
        info[p] = merge(info[2 * p], info[2 * p + 1]);
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (r - l == 1) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        if (x < m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 0, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l >= y || r <= x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        return merge(rangeQuery(2 * p, l, m, x, y), rangeQuery(2 * p + 1, m, r, x, y));
    }
    Info rangeQuery(int l, int r) {
        return rangeQuery(1, 0, n, l, r);
    }
};

struct Point {
    int x, y;
    int val;
    bool operator<(const Point &p) {
        return std::pair(x, y) < std::pair(p.x, p.y);
    }
};

struct Line {
    int a, b;
    int i, j;
    bool operator<(const Line &p) {
        i64 x = 1LL * a * p.b - 1LL * b * p.a;
        if (x == 0)
            return std::pair(i, j) < std::pair(p.i, p.j);
        return x > 0;
    }
};
bool same(const Line &a, const Line &b) {
    return 1LL * a.a * b.b == 1LL * a.b * b.a;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<Point> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i].x >> a[i].y >> a[i].val;
    }
    
    std::sort(a.begin(), a.end());
    
    if (n == 1) {
        std::cout << std::max(a[0].val, 0) << "\n";
        return 0;
    }
    
    std::vector<Line> v;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            v.push_back({a[j].x - a[i].x, a[j].y - a[i].y, i, j});
        }
    }
    
    std::sort(v.begin(), v.end());
    
    SegmentTree<Info> s(n);
    std::vector<int> pos(n);
    for (int i = 0; i < n; i++) {
        s.modify(i, a[i].val);
        pos[i] = i;
    }
    
    i64 ans = s.info[1].ans;
    
    for (int i = 0; i < int(v.size()); i++) {
        int x = v[i].i, y = v[i].j;
        std::swap(pos[x], pos[y]);
        s.modify(pos[x], a[x].val);
        s.modify(pos[y], a[y].val);
        if (i + 1 < int(v.size()) && same(v[i], v[i + 1])) {
            continue;
        }
        ans = std::max(ans, s.info[1].ans);
    }
    
    std::cout << ans << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 444 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 440 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 440 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 436 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 444 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 440 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 440 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 436 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 999 ms 33344 KB Output is correct
34 Correct 989 ms 33348 KB Output is correct
35 Correct 1034 ms 33312 KB Output is correct
36 Correct 984 ms 33308 KB Output is correct
37 Correct 1000 ms 33400 KB Output is correct
38 Correct 1020 ms 33324 KB Output is correct
39 Correct 989 ms 33324 KB Output is correct
40 Correct 995 ms 33392 KB Output is correct
41 Correct 1010 ms 33284 KB Output is correct
42 Correct 1033 ms 33308 KB Output is correct
43 Correct 995 ms 33308 KB Output is correct
44 Correct 962 ms 33400 KB Output is correct
45 Correct 1008 ms 33340 KB Output is correct
46 Correct 989 ms 33272 KB Output is correct
47 Correct 993 ms 33308 KB Output is correct
48 Correct 982 ms 33320 KB Output is correct
49 Correct 973 ms 33308 KB Output is correct
50 Correct 977 ms 33308 KB Output is correct
51 Correct 971 ms 33320 KB Output is correct
52 Correct 966 ms 33328 KB Output is correct
53 Correct 972 ms 33308 KB Output is correct
54 Correct 956 ms 33368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 444 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 440 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 440 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 436 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 444 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 999 ms 33344 KB Output is correct
34 Correct 989 ms 33348 KB Output is correct
35 Correct 1034 ms 33312 KB Output is correct
36 Correct 984 ms 33308 KB Output is correct
37 Correct 1000 ms 33400 KB Output is correct
38 Correct 1020 ms 33324 KB Output is correct
39 Correct 989 ms 33324 KB Output is correct
40 Correct 995 ms 33392 KB Output is correct
41 Correct 1010 ms 33284 KB Output is correct
42 Correct 1033 ms 33308 KB Output is correct
43 Correct 995 ms 33308 KB Output is correct
44 Correct 962 ms 33400 KB Output is correct
45 Correct 1008 ms 33340 KB Output is correct
46 Correct 989 ms 33272 KB Output is correct
47 Correct 993 ms 33308 KB Output is correct
48 Correct 982 ms 33320 KB Output is correct
49 Correct 973 ms 33308 KB Output is correct
50 Correct 977 ms 33308 KB Output is correct
51 Correct 971 ms 33320 KB Output is correct
52 Correct 966 ms 33328 KB Output is correct
53 Correct 972 ms 33308 KB Output is correct
54 Correct 956 ms 33368 KB Output is correct
55 Correct 973 ms 33352 KB Output is correct
56 Correct 983 ms 33308 KB Output is correct
57 Correct 983 ms 33276 KB Output is correct
58 Correct 976 ms 33304 KB Output is correct
59 Correct 980 ms 33352 KB Output is correct
60 Correct 979 ms 33308 KB Output is correct
61 Correct 1010 ms 33440 KB Output is correct
62 Correct 980 ms 33456 KB Output is correct
63 Correct 985 ms 33316 KB Output is correct
64 Correct 986 ms 33372 KB Output is correct
65 Correct 972 ms 33364 KB Output is correct
66 Correct 982 ms 33316 KB Output is correct
67 Correct 962 ms 33312 KB Output is correct
68 Correct 971 ms 33308 KB Output is correct
69 Correct 968 ms 33344 KB Output is correct
70 Correct 988 ms 33348 KB Output is correct
71 Correct 977 ms 33348 KB Output is correct
72 Correct 963 ms 33296 KB Output is correct
73 Correct 957 ms 33316 KB Output is correct
74 Correct 966 ms 33332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 0 ms 312 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 3 ms 444 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 3 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 440 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 440 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 436 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 444 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 999 ms 33344 KB Output is correct
49 Correct 989 ms 33348 KB Output is correct
50 Correct 1034 ms 33312 KB Output is correct
51 Correct 984 ms 33308 KB Output is correct
52 Correct 1000 ms 33400 KB Output is correct
53 Correct 1020 ms 33324 KB Output is correct
54 Correct 989 ms 33324 KB Output is correct
55 Correct 995 ms 33392 KB Output is correct
56 Correct 1010 ms 33284 KB Output is correct
57 Correct 1033 ms 33308 KB Output is correct
58 Correct 995 ms 33308 KB Output is correct
59 Correct 962 ms 33400 KB Output is correct
60 Correct 1008 ms 33340 KB Output is correct
61 Correct 989 ms 33272 KB Output is correct
62 Correct 993 ms 33308 KB Output is correct
63 Correct 982 ms 33320 KB Output is correct
64 Correct 973 ms 33308 KB Output is correct
65 Correct 977 ms 33308 KB Output is correct
66 Correct 971 ms 33320 KB Output is correct
67 Correct 966 ms 33328 KB Output is correct
68 Correct 972 ms 33308 KB Output is correct
69 Correct 956 ms 33368 KB Output is correct
70 Correct 973 ms 33352 KB Output is correct
71 Correct 983 ms 33308 KB Output is correct
72 Correct 983 ms 33276 KB Output is correct
73 Correct 976 ms 33304 KB Output is correct
74 Correct 980 ms 33352 KB Output is correct
75 Correct 979 ms 33308 KB Output is correct
76 Correct 1010 ms 33440 KB Output is correct
77 Correct 980 ms 33456 KB Output is correct
78 Correct 985 ms 33316 KB Output is correct
79 Correct 986 ms 33372 KB Output is correct
80 Correct 972 ms 33364 KB Output is correct
81 Correct 982 ms 33316 KB Output is correct
82 Correct 962 ms 33312 KB Output is correct
83 Correct 971 ms 33308 KB Output is correct
84 Correct 968 ms 33344 KB Output is correct
85 Correct 988 ms 33348 KB Output is correct
86 Correct 977 ms 33348 KB Output is correct
87 Correct 963 ms 33296 KB Output is correct
88 Correct 957 ms 33316 KB Output is correct
89 Correct 966 ms 33332 KB Output is correct
90 Correct 967 ms 33308 KB Output is correct
91 Correct 971 ms 33328 KB Output is correct
92 Correct 968 ms 33296 KB Output is correct
93 Correct 957 ms 33312 KB Output is correct
94 Correct 959 ms 33404 KB Output is correct
95 Correct 954 ms 33316 KB Output is correct
96 Correct 956 ms 33308 KB Output is correct
97 Correct 960 ms 33340 KB Output is correct
98 Correct 959 ms 33344 KB Output is correct
99 Correct 964 ms 33284 KB Output is correct
100 Correct 850 ms 33320 KB Output is correct
101 Correct 834 ms 33316 KB Output is correct
102 Correct 831 ms 33320 KB Output is correct
103 Correct 830 ms 33300 KB Output is correct
104 Correct 832 ms 33296 KB Output is correct
105 Correct 871 ms 33308 KB Output is correct
106 Correct 870 ms 33316 KB Output is correct
107 Correct 889 ms 33316 KB Output is correct
108 Correct 865 ms 33328 KB Output is correct
109 Correct 862 ms 33292 KB Output is correct
110 Correct 928 ms 33308 KB Output is correct
111 Correct 945 ms 33348 KB Output is correct
112 Correct 925 ms 33320 KB Output is correct
113 Correct 913 ms 33304 KB Output is correct
114 Correct 923 ms 33324 KB Output is correct
115 Correct 921 ms 33316 KB Output is correct
116 Correct 933 ms 33324 KB Output is correct
117 Correct 935 ms 33308 KB Output is correct
118 Correct 928 ms 33336 KB Output is correct
119 Correct 923 ms 33308 KB Output is correct
120 Correct 0 ms 204 KB Output is correct
121 Correct 0 ms 204 KB Output is correct
122 Correct 974 ms 33496 KB Output is correct
123 Correct 974 ms 33324 KB Output is correct
124 Correct 987 ms 33336 KB Output is correct
125 Correct 972 ms 33308 KB Output is correct
126 Correct 961 ms 33308 KB Output is correct
127 Correct 985 ms 33376 KB Output is correct
128 Correct 966 ms 33308 KB Output is correct
129 Correct 967 ms 33380 KB Output is correct
130 Correct 949 ms 33336 KB Output is correct
131 Correct 978 ms 33320 KB Output is correct
132 Correct 953 ms 33392 KB Output is correct
133 Correct 960 ms 33324 KB Output is correct