Submission #949867

# Submission time Handle Problem Language Result Execution time Memory
949867 2024-03-19T19:14:45 Z dimashhh Bulldozer (JOI17_bulldozer) C++17
100 / 100
1257 ms 107164 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 4e5+ 5, MOD = 998244353;
#define int ll
int n,pos[N],t[N];
ll x[N],y[N],w[N];
vector<array<ll,3>> a;
struct node{
    ll res,mxl,mxr,sum;
};
node T[N * 4];
node merge(node l,node r){
    node ret;
    ret.sum = l.sum + r.sum;
    ret.res = max({l.res,r.res});
    ret.res = max(ret.res,l.mxr + r.mxl);
    ret.mxr = max(r.mxr,r.sum + l.mxr);
    ret.mxl = max(l.mxl,l.sum + r.mxl);
    return ret;
}
void upd(int pos,ll val,int v = 1,int tl = 1,int tr = n){
    if(tl == tr){
        T[v].sum = val;
        T[v].res = T[v].mxr = T[v].mxl = max(0ll,val);
    }else{
        int tm = (tl + tr) >> 1;
        if(pos <= tm) upd(pos,val,v+v,tl,tm);
        else upd(pos,val,v+v+1,tm+1,tr);
        T[v] = merge(T[v+v],T[v+v+1]);
    }
}
void out(int v = 1,int tl = 1,int tr = n){
    if(tl == tr){
        cout << tl << ' ' << T[v].sum << '\n';
    }else{
        int tm = (tl + tr) >> 1;
        out(v+v,tl,tm);
        out(v+v+1,tm+1,tr);
    }
}
void test() {
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> x[i] >> y[i] >> w[i];
    }
    if(n == 1){
        cout << max(0ll,w[1]) << '\n';
        return;
    }
    vector<pair<long double,pair<int,int>>> cur;
    for(int i = 1;i <= n;i++){
        for(int j = i+1;j <= n;j++){
            long double val;
            if(x[i] == x[j]) val = 2e9;
            else val = (long double)(y[j]-y[i]) / (long double)(x[j] - x[i]);
            cur.push_back({val,{i,j}});
        }
    }
    ll res = 0;
    sort(cur.rbegin(),cur.rend());
    int ii = cur[0].second.first,jj = cur[0].second.second;
    for(int i = n;i >= 1;i--){
        if(x[ii] == x[jj]){
            a.push_back({x[i],y[i],i});
        }else{
            a.push_back({x[i],-y[i],i});
        }
    }
    sort(a.begin(),a.end());
    for(int i = 0;i < (int)a.size();i++){
        pos[a[i][2]] = i + 1;
        t[i + 1] = a[i][2];
        upd(i+1,w[a[i][2]]);
    }
    for(int i = 0;i < (int)cur.size();i++){
//        for(int j = 1;j <= n;j++){
//            cout << t[j] << ' ';
//        }
//        cout << '\n';
        vector<pair<int,int>> ss,s1;
        for(int j = i;j <= (int)cur.size();j++){
            if(j == (int)cur.size() || cur[j].first != cur[i].first){
                i = j - 1;
                break;
            }
            int L = min(pos[cur[j].second.first], pos[cur[j].second.second]), R = max(pos[cur[j].second.first],
                                                                                      pos[cur[j].second.second]);
            ss.push_back({L,R});
        }
        vector<ll> sums;
        sort(ss.begin(),ss.end());
        ll mn = 0,curs = 0;
        ll max_checked;
        for(int j = 0;j < (int)ss.size();j++) {
            if (j && max_checked >= ss[j].second) continue;
            int mx = ss[j].second;
            for (int k = j; k <= (int) ss.size(); k++) {
                if (k == (int) ss.size() || ss[k].first != ss[j].first) {
                    j = k - 1;
                    break;
                }
                max_checked = ss[k].second;
                mx = ss[k].second;
            }
            int l = ss[j].first, r = mx;
            s1.push_back({l, r});
//            cout << l << ' ' << r << '\n';
            while (l < r) {
                swap(t[l], t[r]);
                upd(l, w[t[l]]);
                upd(r, w[t[r]]);
                pos[t[l]] = l;
                pos[t[r]] = r;
                l++;
                r--;
            }
        }
//        cout << T[1].res << "x\n";
//        cout << '\n';
//        for(int j = 1;j <= n;j++){
//            cout << j << ' ' << w[t[j]] << '\n';
//        }
//        cout << '\n';
        for(auto [L,R]:s1){
            ll f = w[t[L]];
//            cout << L << ' ' << R << "x\n";
            for(int j = L + 1;j <= R;j++){
//                upd(j,0);
                f += w[t[j]];
            }
//            upd(L,f);
        }
//        cout << '\n';
//        out();
//        cout << T[1].res << '\n';
        res = max(res,T[1].res);
        for(auto [L,R]:s1){
            for(int j = L;j <= R;j++){
//                upd(j,w[t[j]]);
            }
        }
    }
    cout << res << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int T = 1;
//    cin >> T;
    while(T--){
        test();
    }
}

Compilation message

bulldozer.cpp: In function 'void test()':
bulldozer.cpp:96:12: warning: unused variable 'mn' [-Wunused-variable]
   96 |         ll mn = 0,curs = 0;
      |            ^~
bulldozer.cpp:96:19: warning: unused variable 'curs' [-Wunused-variable]
   96 |         ll mn = 0,curs = 0;
      |                   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10976 KB Output is correct
2 Correct 2 ms 10976 KB Output is correct
3 Correct 2 ms 10976 KB Output is correct
4 Correct 3 ms 10976 KB Output is correct
5 Correct 2 ms 10972 KB Output is correct
6 Correct 2 ms 10976 KB Output is correct
7 Correct 2 ms 10976 KB Output is correct
8 Correct 3 ms 10972 KB Output is correct
9 Correct 2 ms 10972 KB Output is correct
10 Correct 2 ms 10972 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10740 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10976 KB Output is correct
2 Correct 3 ms 10976 KB Output is correct
3 Correct 4 ms 10972 KB Output is correct
4 Correct 4 ms 10972 KB Output is correct
5 Correct 4 ms 10976 KB Output is correct
6 Correct 4 ms 10976 KB Output is correct
7 Correct 3 ms 10976 KB Output is correct
8 Correct 4 ms 10976 KB Output is correct
9 Correct 4 ms 10976 KB Output is correct
10 Correct 4 ms 10976 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 4 ms 10972 KB Output is correct
22 Correct 4 ms 10976 KB Output is correct
23 Correct 3 ms 10976 KB Output is correct
24 Correct 4 ms 11024 KB Output is correct
25 Correct 4 ms 10976 KB Output is correct
26 Correct 3 ms 10976 KB Output is correct
27 Correct 4 ms 10976 KB Output is correct
28 Correct 4 ms 10976 KB Output is correct
29 Correct 4 ms 10976 KB Output is correct
30 Correct 4 ms 10976 KB Output is correct
31 Correct 4 ms 10976 KB Output is correct
32 Correct 4 ms 10976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10976 KB Output is correct
2 Correct 3 ms 10976 KB Output is correct
3 Correct 4 ms 10972 KB Output is correct
4 Correct 4 ms 10972 KB Output is correct
5 Correct 4 ms 10976 KB Output is correct
6 Correct 4 ms 10976 KB Output is correct
7 Correct 3 ms 10976 KB Output is correct
8 Correct 4 ms 10976 KB Output is correct
9 Correct 4 ms 10976 KB Output is correct
10 Correct 4 ms 10976 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 4 ms 10972 KB Output is correct
22 Correct 4 ms 10976 KB Output is correct
23 Correct 3 ms 10976 KB Output is correct
24 Correct 4 ms 11024 KB Output is correct
25 Correct 4 ms 10976 KB Output is correct
26 Correct 3 ms 10976 KB Output is correct
27 Correct 4 ms 10976 KB Output is correct
28 Correct 4 ms 10976 KB Output is correct
29 Correct 4 ms 10976 KB Output is correct
30 Correct 4 ms 10976 KB Output is correct
31 Correct 4 ms 10976 KB Output is correct
32 Correct 4 ms 10976 KB Output is correct
33 Correct 1222 ms 75340 KB Output is correct
34 Correct 1217 ms 74868 KB Output is correct
35 Correct 1206 ms 73604 KB Output is correct
36 Correct 1229 ms 75168 KB Output is correct
37 Correct 1234 ms 74280 KB Output is correct
38 Correct 1230 ms 74436 KB Output is correct
39 Correct 1222 ms 73548 KB Output is correct
40 Correct 1237 ms 73760 KB Output is correct
41 Correct 1211 ms 75156 KB Output is correct
42 Correct 1202 ms 75168 KB Output is correct
43 Correct 1244 ms 73996 KB Output is correct
44 Correct 1205 ms 74960 KB Output is correct
45 Correct 1206 ms 75692 KB Output is correct
46 Correct 1196 ms 74064 KB Output is correct
47 Correct 1224 ms 73632 KB Output is correct
48 Correct 1202 ms 73768 KB Output is correct
49 Correct 1206 ms 74740 KB Output is correct
50 Correct 1224 ms 75428 KB Output is correct
51 Correct 1213 ms 75400 KB Output is correct
52 Correct 1193 ms 75124 KB Output is correct
53 Correct 1201 ms 73632 KB Output is correct
54 Correct 1206 ms 73860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 10976 KB Output is correct
2 Correct 3 ms 10976 KB Output is correct
3 Correct 4 ms 10972 KB Output is correct
4 Correct 4 ms 10972 KB Output is correct
5 Correct 4 ms 10976 KB Output is correct
6 Correct 4 ms 10976 KB Output is correct
7 Correct 3 ms 10976 KB Output is correct
8 Correct 4 ms 10976 KB Output is correct
9 Correct 4 ms 10976 KB Output is correct
10 Correct 4 ms 10976 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 4 ms 10972 KB Output is correct
22 Correct 4 ms 10976 KB Output is correct
23 Correct 3 ms 10976 KB Output is correct
24 Correct 4 ms 11024 KB Output is correct
25 Correct 4 ms 10976 KB Output is correct
26 Correct 3 ms 10976 KB Output is correct
27 Correct 4 ms 10976 KB Output is correct
28 Correct 4 ms 10976 KB Output is correct
29 Correct 4 ms 10976 KB Output is correct
30 Correct 4 ms 10976 KB Output is correct
31 Correct 4 ms 10976 KB Output is correct
32 Correct 4 ms 10976 KB Output is correct
33 Correct 1222 ms 75340 KB Output is correct
34 Correct 1217 ms 74868 KB Output is correct
35 Correct 1206 ms 73604 KB Output is correct
36 Correct 1229 ms 75168 KB Output is correct
37 Correct 1234 ms 74280 KB Output is correct
38 Correct 1230 ms 74436 KB Output is correct
39 Correct 1222 ms 73548 KB Output is correct
40 Correct 1237 ms 73760 KB Output is correct
41 Correct 1211 ms 75156 KB Output is correct
42 Correct 1202 ms 75168 KB Output is correct
43 Correct 1244 ms 73996 KB Output is correct
44 Correct 1205 ms 74960 KB Output is correct
45 Correct 1206 ms 75692 KB Output is correct
46 Correct 1196 ms 74064 KB Output is correct
47 Correct 1224 ms 73632 KB Output is correct
48 Correct 1202 ms 73768 KB Output is correct
49 Correct 1206 ms 74740 KB Output is correct
50 Correct 1224 ms 75428 KB Output is correct
51 Correct 1213 ms 75400 KB Output is correct
52 Correct 1193 ms 75124 KB Output is correct
53 Correct 1201 ms 73632 KB Output is correct
54 Correct 1206 ms 73860 KB Output is correct
55 Correct 1217 ms 73888 KB Output is correct
56 Correct 1232 ms 73732 KB Output is correct
57 Correct 1251 ms 75420 KB Output is correct
58 Correct 1241 ms 73984 KB Output is correct
59 Correct 1205 ms 75388 KB Output is correct
60 Correct 1234 ms 75424 KB Output is correct
61 Correct 1217 ms 75168 KB Output is correct
62 Correct 1211 ms 74580 KB Output is correct
63 Correct 1217 ms 75420 KB Output is correct
64 Correct 1211 ms 73628 KB Output is correct
65 Correct 1214 ms 74636 KB Output is correct
66 Correct 1206 ms 74172 KB Output is correct
67 Correct 1216 ms 74560 KB Output is correct
68 Correct 1250 ms 74108 KB Output is correct
69 Correct 1210 ms 74448 KB Output is correct
70 Correct 1200 ms 74400 KB Output is correct
71 Correct 1257 ms 75452 KB Output is correct
72 Correct 1227 ms 74256 KB Output is correct
73 Correct 1222 ms 74308 KB Output is correct
74 Correct 1216 ms 73832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10976 KB Output is correct
2 Correct 2 ms 10976 KB Output is correct
3 Correct 2 ms 10976 KB Output is correct
4 Correct 3 ms 10976 KB Output is correct
5 Correct 2 ms 10972 KB Output is correct
6 Correct 2 ms 10976 KB Output is correct
7 Correct 2 ms 10976 KB Output is correct
8 Correct 3 ms 10972 KB Output is correct
9 Correct 2 ms 10972 KB Output is correct
10 Correct 2 ms 10972 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 2 ms 10740 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 4 ms 10976 KB Output is correct
17 Correct 3 ms 10976 KB Output is correct
18 Correct 4 ms 10972 KB Output is correct
19 Correct 4 ms 10972 KB Output is correct
20 Correct 4 ms 10976 KB Output is correct
21 Correct 4 ms 10976 KB Output is correct
22 Correct 3 ms 10976 KB Output is correct
23 Correct 4 ms 10976 KB Output is correct
24 Correct 4 ms 10976 KB Output is correct
25 Correct 4 ms 10976 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 10588 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 1 ms 10588 KB Output is correct
31 Correct 2 ms 10588 KB Output is correct
32 Correct 2 ms 10588 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 4 ms 10972 KB Output is correct
37 Correct 4 ms 10976 KB Output is correct
38 Correct 3 ms 10976 KB Output is correct
39 Correct 4 ms 11024 KB Output is correct
40 Correct 4 ms 10976 KB Output is correct
41 Correct 3 ms 10976 KB Output is correct
42 Correct 4 ms 10976 KB Output is correct
43 Correct 4 ms 10976 KB Output is correct
44 Correct 4 ms 10976 KB Output is correct
45 Correct 4 ms 10976 KB Output is correct
46 Correct 4 ms 10976 KB Output is correct
47 Correct 4 ms 10976 KB Output is correct
48 Correct 1222 ms 75340 KB Output is correct
49 Correct 1217 ms 74868 KB Output is correct
50 Correct 1206 ms 73604 KB Output is correct
51 Correct 1229 ms 75168 KB Output is correct
52 Correct 1234 ms 74280 KB Output is correct
53 Correct 1230 ms 74436 KB Output is correct
54 Correct 1222 ms 73548 KB Output is correct
55 Correct 1237 ms 73760 KB Output is correct
56 Correct 1211 ms 75156 KB Output is correct
57 Correct 1202 ms 75168 KB Output is correct
58 Correct 1244 ms 73996 KB Output is correct
59 Correct 1205 ms 74960 KB Output is correct
60 Correct 1206 ms 75692 KB Output is correct
61 Correct 1196 ms 74064 KB Output is correct
62 Correct 1224 ms 73632 KB Output is correct
63 Correct 1202 ms 73768 KB Output is correct
64 Correct 1206 ms 74740 KB Output is correct
65 Correct 1224 ms 75428 KB Output is correct
66 Correct 1213 ms 75400 KB Output is correct
67 Correct 1193 ms 75124 KB Output is correct
68 Correct 1201 ms 73632 KB Output is correct
69 Correct 1206 ms 73860 KB Output is correct
70 Correct 1217 ms 73888 KB Output is correct
71 Correct 1232 ms 73732 KB Output is correct
72 Correct 1251 ms 75420 KB Output is correct
73 Correct 1241 ms 73984 KB Output is correct
74 Correct 1205 ms 75388 KB Output is correct
75 Correct 1234 ms 75424 KB Output is correct
76 Correct 1217 ms 75168 KB Output is correct
77 Correct 1211 ms 74580 KB Output is correct
78 Correct 1217 ms 75420 KB Output is correct
79 Correct 1211 ms 73628 KB Output is correct
80 Correct 1214 ms 74636 KB Output is correct
81 Correct 1206 ms 74172 KB Output is correct
82 Correct 1216 ms 74560 KB Output is correct
83 Correct 1250 ms 74108 KB Output is correct
84 Correct 1210 ms 74448 KB Output is correct
85 Correct 1200 ms 74400 KB Output is correct
86 Correct 1257 ms 75452 KB Output is correct
87 Correct 1227 ms 74256 KB Output is correct
88 Correct 1222 ms 74308 KB Output is correct
89 Correct 1216 ms 73832 KB Output is correct
90 Correct 1212 ms 75164 KB Output is correct
91 Correct 1243 ms 74432 KB Output is correct
92 Correct 1239 ms 75168 KB Output is correct
93 Correct 1205 ms 73880 KB Output is correct
94 Correct 1209 ms 75160 KB Output is correct
95 Correct 1215 ms 74688 KB Output is correct
96 Correct 1223 ms 73656 KB Output is correct
97 Correct 1233 ms 75136 KB Output is correct
98 Correct 1232 ms 74136 KB Output is correct
99 Correct 1231 ms 74056 KB Output is correct
100 Correct 847 ms 107164 KB Output is correct
101 Correct 821 ms 106404 KB Output is correct
102 Correct 878 ms 107076 KB Output is correct
103 Correct 901 ms 105884 KB Output is correct
104 Correct 875 ms 106912 KB Output is correct
105 Correct 1008 ms 102364 KB Output is correct
106 Correct 963 ms 100732 KB Output is correct
107 Correct 983 ms 103308 KB Output is correct
108 Correct 986 ms 101088 KB Output is correct
109 Correct 1002 ms 103328 KB Output is correct
110 Correct 925 ms 75424 KB Output is correct
111 Correct 923 ms 76196 KB Output is correct
112 Correct 923 ms 76052 KB Output is correct
113 Correct 942 ms 76444 KB Output is correct
114 Correct 952 ms 75172 KB Output is correct
115 Correct 928 ms 74904 KB Output is correct
116 Correct 955 ms 75164 KB Output is correct
117 Correct 935 ms 76188 KB Output is correct
118 Correct 928 ms 75652 KB Output is correct
119 Correct 938 ms 74716 KB Output is correct
120 Correct 2 ms 10588 KB Output is correct
121 Correct 1 ms 10584 KB Output is correct
122 Correct 1209 ms 74548 KB Output is correct
123 Correct 1239 ms 75404 KB Output is correct
124 Correct 1205 ms 74220 KB Output is correct
125 Correct 1216 ms 74432 KB Output is correct
126 Correct 1209 ms 75372 KB Output is correct
127 Correct 1222 ms 75096 KB Output is correct
128 Correct 1235 ms 75416 KB Output is correct
129 Correct 1225 ms 74944 KB Output is correct
130 Correct 1209 ms 75416 KB Output is correct
131 Correct 1202 ms 74168 KB Output is correct
132 Correct 1222 ms 75064 KB Output is correct
133 Correct 1202 ms 74412 KB Output is correct