답안 #1110147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110147 2024-11-08T20:51:25 Z vladilius Bulldozer (JOI17_bulldozer) C++17
100 / 100
792 ms 35884 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

struct ST{
    struct node{
        ll pr, sf, mx, s;
    };
    vector<node> t;
    int n;
    ST(int ns){
        n = ns;
        t.resize(4 * n);
    }
    void upd(int v, int tl, int tr, int& p, int& x){
        if (tl == tr){
            t[v].s = x;
            t[v].pr = t[v].sf = t[v].mx = max(0, x);
            return;
        }
        int tm = (tl + tr) / 2, vv = 2 * v;
        if (p <= tm){
            upd(vv, tl, tm, p, x);
        }
        else {
            upd(vv + 1, tm + 1, tr, p, x);
        }
        t[v].s = t[vv].s + t[vv + 1].s;
        t[v].mx = max({t[vv].mx, t[vv + 1].mx, t[vv].sf + t[vv + 1].pr});
        t[v].pr = max(t[vv].pr, t[vv].s + t[vv + 1].pr);
        t[v].sf = max(t[vv + 1].sf, t[vv + 1].s + t[vv].sf);
    }
    void upd(int p, int x){
        upd(1, 1, n, p, x);
    }
    ll get(){
        return t[1].mx;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n; cin>>n;
    vector<int> x(n + 1), y(n + 1), a(n + 1), f = {0};
    for (int i = 1; i <= n; i++){
        cin>>x[i]>>y[i]>>a[i];
        f.pb(i);
    }
    
    auto cmp = [&](int i, int j){
        if (x[i] == x[j]){
            return y[i] < y[j];
        }
        return x[i] < x[j];
    };
    sort(f.begin() + 1, f.end(), cmp);
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++){
        p[f[i]] = i;
    }
    ST T(n);
    for (int i = 1; i <= n; i++){
        T.upd(p[i], a[i]);
    }
    ll out = T.get();
    
    vector<pair<pii, pii>> all;
    for (int i = 1; i <= n; i++){
        for (int j = i + 1; j <= n; j++){
            if (x[f[i]] != x[f[j]]){
                all.pb({{y[f[j]] - y[f[i]], x[f[j]] - x[f[i]]}, {f[i], f[j]}});
            }
        }
    }
    
    auto cmp1 = [&](pair<pii, pii> a, pair<pii, pii> b){
        auto [u1, v1] = a.ff;
        auto [u2, v2] = b.ff;
        return 1LL * u1 * v2 < 1LL * u2 * v1;
    };
    
    sort(all.begin(), all.end(), cmp1);
    vector<bool> used(n + 1);
    vector<int> ff, pp;
    int i = 0;
    while (i < all.size()){
        int j = i;
        while (j < all.size() && (1LL * all[i].ff.ff * all[j].ff.ss) == (1LL * all[i].ff.ss * all[j].ff.ff)){
            j++;
        }
        
        ll r, q;
        if (j == all.size()){
            r = 2e9 + 1;
            q = 1;
        }
        else {
            r = all[i].ff.ff; r += all[j].ff.ff;
            q = all[i].ff.ss; q += all[j].ff.ss;
        }
        auto cmp2 = [&](int u, int v){
            if (x[u] == x[v]) return y[u] < y[v];
            return q * (y[u] - y[v]) < r * (x[u] - x[v]);
        };
  
        ff.clear(); pp.clear();
        for (int k = i; k < j; k++){
            auto [u, v] = all[k].ss;
            if (!used[u]){
                used[u] = 1;
                ff.pb(u);
                pp.pb(p[u]);
            }
            if (!used[v]){
                used[v] = 1;
                ff.pb(v);
                pp.pb(p[v]);
            }
        }
        sort(ff.begin(), ff.end(), cmp2);
        sort(pp.begin(), pp.end());
        for (int i = 0; i < pp.size(); i++){
            p[ff[i]] = pp[i];
            T.upd(pp[i], a[ff[i]]);
        }
        for (int k = i; k < j; k++){
            auto [u, v] = all[k].ss;
            used[u] = used[v] = 0;
        }
        
        out = max(out, T.get());
        i = j;
    }
    
    cout<<out<<"\n";
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:93:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     while (i < all.size()){
      |            ~~^~~~~~~~~~~~
bulldozer.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         while (j < all.size() && (1LL * all[i].ff.ff * all[j].ff.ss) == (1LL * all[i].ff.ss * all[j].ff.ff)){
      |                ~~^~~~~~~~~~~~
bulldozer.cpp:100:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |         if (j == all.size()){
      |             ~~^~~~~~~~~~~~~
bulldozer.cpp:129:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |         for (int i = 0; i < pp.size(); i++){
      |                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 1 ms 656 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 733 ms 35764 KB Output is correct
34 Correct 701 ms 35700 KB Output is correct
35 Correct 718 ms 35764 KB Output is correct
36 Correct 702 ms 35764 KB Output is correct
37 Correct 740 ms 35764 KB Output is correct
38 Correct 743 ms 35764 KB Output is correct
39 Correct 746 ms 35764 KB Output is correct
40 Correct 783 ms 35764 KB Output is correct
41 Correct 729 ms 35884 KB Output is correct
42 Correct 733 ms 35764 KB Output is correct
43 Correct 744 ms 35764 KB Output is correct
44 Correct 728 ms 35764 KB Output is correct
45 Correct 739 ms 35764 KB Output is correct
46 Correct 712 ms 35764 KB Output is correct
47 Correct 708 ms 35764 KB Output is correct
48 Correct 703 ms 35764 KB Output is correct
49 Correct 724 ms 35764 KB Output is correct
50 Correct 715 ms 35764 KB Output is correct
51 Correct 703 ms 35764 KB Output is correct
52 Correct 697 ms 35764 KB Output is correct
53 Correct 718 ms 35764 KB Output is correct
54 Correct 716 ms 35764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 733 ms 35764 KB Output is correct
34 Correct 701 ms 35700 KB Output is correct
35 Correct 718 ms 35764 KB Output is correct
36 Correct 702 ms 35764 KB Output is correct
37 Correct 740 ms 35764 KB Output is correct
38 Correct 743 ms 35764 KB Output is correct
39 Correct 746 ms 35764 KB Output is correct
40 Correct 783 ms 35764 KB Output is correct
41 Correct 729 ms 35884 KB Output is correct
42 Correct 733 ms 35764 KB Output is correct
43 Correct 744 ms 35764 KB Output is correct
44 Correct 728 ms 35764 KB Output is correct
45 Correct 739 ms 35764 KB Output is correct
46 Correct 712 ms 35764 KB Output is correct
47 Correct 708 ms 35764 KB Output is correct
48 Correct 703 ms 35764 KB Output is correct
49 Correct 724 ms 35764 KB Output is correct
50 Correct 715 ms 35764 KB Output is correct
51 Correct 703 ms 35764 KB Output is correct
52 Correct 697 ms 35764 KB Output is correct
53 Correct 718 ms 35764 KB Output is correct
54 Correct 716 ms 35764 KB Output is correct
55 Correct 752 ms 35764 KB Output is correct
56 Correct 726 ms 35764 KB Output is correct
57 Correct 778 ms 35764 KB Output is correct
58 Correct 734 ms 35764 KB Output is correct
59 Correct 742 ms 35764 KB Output is correct
60 Correct 725 ms 35764 KB Output is correct
61 Correct 739 ms 35764 KB Output is correct
62 Correct 741 ms 35764 KB Output is correct
63 Correct 735 ms 35764 KB Output is correct
64 Correct 710 ms 35764 KB Output is correct
65 Correct 737 ms 35764 KB Output is correct
66 Correct 723 ms 35764 KB Output is correct
67 Correct 709 ms 35732 KB Output is correct
68 Correct 751 ms 35764 KB Output is correct
69 Correct 729 ms 35764 KB Output is correct
70 Correct 708 ms 35764 KB Output is correct
71 Correct 695 ms 35764 KB Output is correct
72 Correct 711 ms 35704 KB Output is correct
73 Correct 740 ms 35764 KB Output is correct
74 Correct 719 ms 35764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 1 ms 656 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 760 KB Output is correct
23 Correct 2 ms 592 KB Output is correct
24 Correct 2 ms 592 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 764 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 2 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 2 ms 592 KB Output is correct
48 Correct 733 ms 35764 KB Output is correct
49 Correct 701 ms 35700 KB Output is correct
50 Correct 718 ms 35764 KB Output is correct
51 Correct 702 ms 35764 KB Output is correct
52 Correct 740 ms 35764 KB Output is correct
53 Correct 743 ms 35764 KB Output is correct
54 Correct 746 ms 35764 KB Output is correct
55 Correct 783 ms 35764 KB Output is correct
56 Correct 729 ms 35884 KB Output is correct
57 Correct 733 ms 35764 KB Output is correct
58 Correct 744 ms 35764 KB Output is correct
59 Correct 728 ms 35764 KB Output is correct
60 Correct 739 ms 35764 KB Output is correct
61 Correct 712 ms 35764 KB Output is correct
62 Correct 708 ms 35764 KB Output is correct
63 Correct 703 ms 35764 KB Output is correct
64 Correct 724 ms 35764 KB Output is correct
65 Correct 715 ms 35764 KB Output is correct
66 Correct 703 ms 35764 KB Output is correct
67 Correct 697 ms 35764 KB Output is correct
68 Correct 718 ms 35764 KB Output is correct
69 Correct 716 ms 35764 KB Output is correct
70 Correct 752 ms 35764 KB Output is correct
71 Correct 726 ms 35764 KB Output is correct
72 Correct 778 ms 35764 KB Output is correct
73 Correct 734 ms 35764 KB Output is correct
74 Correct 742 ms 35764 KB Output is correct
75 Correct 725 ms 35764 KB Output is correct
76 Correct 739 ms 35764 KB Output is correct
77 Correct 741 ms 35764 KB Output is correct
78 Correct 735 ms 35764 KB Output is correct
79 Correct 710 ms 35764 KB Output is correct
80 Correct 737 ms 35764 KB Output is correct
81 Correct 723 ms 35764 KB Output is correct
82 Correct 709 ms 35732 KB Output is correct
83 Correct 751 ms 35764 KB Output is correct
84 Correct 729 ms 35764 KB Output is correct
85 Correct 708 ms 35764 KB Output is correct
86 Correct 695 ms 35764 KB Output is correct
87 Correct 711 ms 35704 KB Output is correct
88 Correct 740 ms 35764 KB Output is correct
89 Correct 719 ms 35764 KB Output is correct
90 Correct 713 ms 35764 KB Output is correct
91 Correct 691 ms 35764 KB Output is correct
92 Correct 722 ms 35764 KB Output is correct
93 Correct 711 ms 35764 KB Output is correct
94 Correct 723 ms 35764 KB Output is correct
95 Correct 722 ms 35728 KB Output is correct
96 Correct 723 ms 35764 KB Output is correct
97 Correct 756 ms 35764 KB Output is correct
98 Correct 714 ms 35764 KB Output is correct
99 Correct 729 ms 35764 KB Output is correct
100 Correct 341 ms 19128 KB Output is correct
101 Correct 319 ms 19128 KB Output is correct
102 Correct 330 ms 19128 KB Output is correct
103 Correct 325 ms 19128 KB Output is correct
104 Correct 345 ms 19128 KB Output is correct
105 Correct 442 ms 35764 KB Output is correct
106 Correct 456 ms 35764 KB Output is correct
107 Correct 454 ms 35764 KB Output is correct
108 Correct 465 ms 35764 KB Output is correct
109 Correct 442 ms 35764 KB Output is correct
110 Correct 579 ms 35764 KB Output is correct
111 Correct 590 ms 35764 KB Output is correct
112 Correct 586 ms 35764 KB Output is correct
113 Correct 606 ms 35764 KB Output is correct
114 Correct 598 ms 35760 KB Output is correct
115 Correct 603 ms 35764 KB Output is correct
116 Correct 618 ms 35764 KB Output is correct
117 Correct 624 ms 35764 KB Output is correct
118 Correct 588 ms 35764 KB Output is correct
119 Correct 600 ms 35764 KB Output is correct
120 Correct 1 ms 336 KB Output is correct
121 Correct 1 ms 336 KB Output is correct
122 Correct 762 ms 35764 KB Output is correct
123 Correct 748 ms 35764 KB Output is correct
124 Correct 762 ms 35644 KB Output is correct
125 Correct 792 ms 35764 KB Output is correct
126 Correct 760 ms 35764 KB Output is correct
127 Correct 727 ms 35796 KB Output is correct
128 Correct 743 ms 35764 KB Output is correct
129 Correct 747 ms 35764 KB Output is correct
130 Correct 710 ms 35764 KB Output is correct
131 Correct 717 ms 35764 KB Output is correct
132 Correct 718 ms 35764 KB Output is correct
133 Correct 771 ms 35764 KB Output is correct