제출 #1125591

#제출 시각아이디문제언어결과실행 시간메모리
1125591steveonalexTeam Contest (JOI22_team)C++20
100 / 100
210 ms22164 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll gcd(ll a, ll b){
    while(a > 0 && b > 0){
        if (a > b) a %= b;
        else b %= a;
    }
    return a + b;
}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n"){
        for(auto item: container) cout << item << separator;
        cout << finish;
    }


template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }


struct FenwickTree{
    int n;
    vector<ll> a;

    FenwickTree(int _n){
        n = _n;
        a.resize(n+1);
    }

    void update(int i, ll v){
        while(i <= n){
            maximize(a[i], v);
            i += LASTBIT(i);
        }
    }

    ll get(int i){
        ll ans = 0;
        while(i > 0){
            maximize(ans, a[i]);
            i -= LASTBIT(i);
        }
        return ans;
    }
};


void solve(){
    int n; cin >> n;
    vector<array<int, 3>> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i][0] >> a[i][1] >> a[i][2];
    
    vector<int> X = {0}, Y = {0};
    for(int i = 0; i < n; ++i){
        X.push_back(a[i][1]);
        Y.push_back(a[i][2]);
    }
    remove_dup(X); remove_dup(Y);
    for(int i = 0; i < n; ++i){
        a[i][1] = lower_bound(ALL(X), a[i][1]) - X.begin();
        a[i][2] = lower_bound(ALL(Y), a[i][2]) - Y.begin();
    }


    map<int, vector<pair<int, int>>> mp;
    for(int i = 0; i < n; ++i) {
        mp[a[i][0]].push_back({a[i][1], a[i][2]});
    }

    int x = X.size() - 1, y = Y.size() - 1;
    FenwickTree bit1(x), bit2(y);

    int ma_x = 0, ma_y = 0;
    ll ans = -1;
    for(auto i: mp){
        vector<pair<int, int>> cur = i.second;
        for(auto j: cur){
            if (X[j.first] < ma_x && Y[j.second] < ma_y) {
                maximize(ans, i.first + ma_x + ma_y);
            }
        }
        for(auto j: cur){
            int cur1 = bit1.get(j.first - 1), cur2 = bit2.get(j.second - 1);
            if (cur1 > j.second) {
                maximize(ma_x, X[j.first]);
                maximize(ma_y, Y[cur1]);
            }
            if (cur2 > j.first) {
                maximize(ma_y, Y[j.second]);
                maximize(ma_x, X[cur2]);
            }

            bit1.update(j.first, j.second);
            bit2.update(j.second, j.first);
        }
    }
    cout << ans << "\n";
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    clock_t start = clock();

    solve();

    cerr << "Time elapsed: " << clock() - start << "ms!\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...