Submission #949832

# Submission time Handle Problem Language Result Execution time Memory
949832 2024-03-19T18:27:24 Z dimashhh Bulldozer (JOI17_bulldozer) C++17
0 / 100
6 ms 11100 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 4e5+ 5, MOD = 998244353;

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 test() {
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> x[i] >> y[i] >> w[i];
        a.push_back({x[i],-y[i],i});
    }
    if(n == 1){
        cout << max(0ll,w[1]) << '\n';
        return;
    }
    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]]);
    }
    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 = (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());
    for(int i = 0;i < (int)cur.size();i++){
        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});
            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--;
            }
        }
        for(auto [L,R]:s1){
            ll f = w[t[L]];
            for(int j = L + 1;j <= R;j++){
                upd(j,0);
                f += w[t[j]];
            }
            upd(L,f);
        }
        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:74:12: warning: unused variable 'mn' [-Wunused-variable]
   74 |         ll mn = 0,curs = 0;
      |            ^~
bulldozer.cpp:74:19: warning: unused variable 'curs' [-Wunused-variable]
   74 |         ll mn = 0,curs = 0;
      |                   ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 11100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11100 KB Output is correct
2 Correct 6 ms 11100 KB Output is correct
3 Correct 6 ms 11100 KB Output is correct
4 Correct 6 ms 11100 KB Output is correct
5 Correct 5 ms 11100 KB Output is correct
6 Correct 6 ms 11100 KB Output is correct
7 Correct 6 ms 11100 KB Output is correct
8 Correct 5 ms 11100 KB Output is correct
9 Correct 6 ms 11100 KB Output is correct
10 Correct 6 ms 11100 KB Output is correct
11 Correct 4 ms 6584 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Incorrect 2 ms 10588 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11100 KB Output is correct
2 Correct 6 ms 11100 KB Output is correct
3 Correct 6 ms 11100 KB Output is correct
4 Correct 6 ms 11100 KB Output is correct
5 Correct 5 ms 11100 KB Output is correct
6 Correct 6 ms 11100 KB Output is correct
7 Correct 6 ms 11100 KB Output is correct
8 Correct 5 ms 11100 KB Output is correct
9 Correct 6 ms 11100 KB Output is correct
10 Correct 6 ms 11100 KB Output is correct
11 Correct 4 ms 6584 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Incorrect 2 ms 10588 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11100 KB Output is correct
2 Correct 6 ms 11100 KB Output is correct
3 Correct 6 ms 11100 KB Output is correct
4 Correct 6 ms 11100 KB Output is correct
5 Correct 5 ms 11100 KB Output is correct
6 Correct 6 ms 11100 KB Output is correct
7 Correct 6 ms 11100 KB Output is correct
8 Correct 5 ms 11100 KB Output is correct
9 Correct 6 ms 11100 KB Output is correct
10 Correct 6 ms 11100 KB Output is correct
11 Correct 4 ms 6584 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Incorrect 2 ms 10588 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 11100 KB Output isn't correct
2 Halted 0 ms 0 KB -