답안 #965093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965093 2024-04-18T06:08:27 Z angella Team Contest (JOI22_team) C++17
0 / 100
296 ms 16308 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

int n, a[3][N], mx[2*N], mn[2*N], ans;
vector<int> comp[3], vec[N];

int get(int id, int x) {
    return lower_bound(all(comp[id]), x) - comp[id].begin() + 1;
}

void upd(int ind, int val) {
    mn[ind] = min(mn[ind], val), mx[ind] = max(mx[ind], val);
    ind/=2;
    while(ind > 0) {
        mx[ind] = max(mx[2*ind], mx[2*ind+1]);
        mn[ind] = min(mn[2*ind], mn[2*ind+1]);
        ind/=2;
    }
}

int qrymx(int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
    if(lc>=r) return 0;
    if(rc<=r) return mx[ind];
    int mid=(lc+rc)/2;
    return max(qrymx(r,2*ind,lc,mid), qrymx(r,2*ind+1,mid,rc));
}

int qry(int l, int val, int ind=1, int lc=1, int rc=(1<<lg)+1) {
    if(rc<=l) return 0;
    if(ind>=(1<<lg)) {
        if(mn[ind] < val) return comp[1][lc-1];
        return 0;
    }
    int mid = (lc+rc)/2;
    if(lc>=l) {
        if(mn[2*ind+1] < val) return qry(l,val,2*ind+1,mid,rc);
        return qry(l,val,2*ind,lc,mid);
    }
    if(mn[2*ind+1] < val) return qry(l,val,2*ind+1,mid,rc);
    return qry(l,val,2*ind,lc,mid);
}

void solve() {
    for(int i=1; i<=n; i++) {
        vec[get(0, a[0][i])].pb(i);
    }
    for(int i=1; i<=n; i++) {
    for(auto it : vec[i]) {
        int maxi=qrymx(get(1,a[1][it])+1);
        int res = qry(get(1,a[1][it])+1, maxi);
if(res<1e9 && res != 0 && maxi != 0) ans = max(ans,a[0][it]+maxi+res);
    }
    for(auto it : vec[i]) {
        upd(get(1,a[1][it])+(1<<lg)-1, a[2][it]);
    }
    }
}

void reset() {
    fill(mx, mx+2*N, 0);
    fill(mn, mn+2*N, 1e9);
    for(int i=1; i<=n; i++) vec[i].clear();
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n;
    for(int i=1; i<=n; i++) {
        for(int j=0; j<3; j++) {
            cin>>a[j][i]; comp[j].pb(a[j][i]);
        }
    }
    for(int i=0; i<3; i++) {
        sort(all(comp[i])); 
        comp[i].resize(unique(all(comp[i]))-comp[i].begin());
    }
    fill(mn, mn+2*N, 1e9);
    solve();
    reset();
    
    for(int i=1; i<=n; i++) swap(a[1][i], a[2][i]);
    swap(comp[1], comp[2]);
    solve();
    reset();
    
    for(int i=1; i<=n; i++) swap(a[1][i], a[0][i]);
    swap(comp[1], comp[0]);
    solve();
    reset();
    
    for(int i=1; i<=n; i++) swap(a[1][i], a[2][i]);
    swap(comp[1], comp[2]);
    solve();
    reset();

    for(int i=1; i<=n; i++) swap(a[1][i], a[0][i]);
    swap(comp[1], comp[0]);
    solve();
    reset();
    
    for(int i=1; i<=n; i++) swap(a[1][i], a[2][i]);
    swap(comp[1], comp[2]);
    solve();

    cout<<(ans==0 ? -1 : ans)<<endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12124 KB Output is correct
2 Correct 6 ms 12024 KB Output is correct
3 Correct 11 ms 12188 KB Output is correct
4 Correct 7 ms 12124 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 6 ms 12136 KB Output is correct
7 Correct 10 ms 12124 KB Output is correct
8 Correct 8 ms 12120 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 6 ms 12124 KB Output is correct
12 Correct 5 ms 12124 KB Output is correct
13 Correct 8 ms 12444 KB Output is correct
14 Correct 7 ms 12376 KB Output is correct
15 Incorrect 9 ms 12124 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12124 KB Output is correct
2 Correct 6 ms 12024 KB Output is correct
3 Correct 11 ms 12188 KB Output is correct
4 Correct 7 ms 12124 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 6 ms 12136 KB Output is correct
7 Correct 10 ms 12124 KB Output is correct
8 Correct 8 ms 12120 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 6 ms 12124 KB Output is correct
12 Correct 5 ms 12124 KB Output is correct
13 Correct 8 ms 12444 KB Output is correct
14 Correct 7 ms 12376 KB Output is correct
15 Incorrect 9 ms 12124 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 6 ms 12120 KB Output is correct
3 Correct 7 ms 12124 KB Output is correct
4 Correct 5 ms 12120 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 5 ms 12124 KB Output is correct
7 Correct 8 ms 12216 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 5 ms 12280 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 296 ms 16308 KB Output is correct
12 Incorrect 195 ms 15296 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 6 ms 12120 KB Output is correct
3 Correct 7 ms 12124 KB Output is correct
4 Correct 5 ms 12120 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 5 ms 12124 KB Output is correct
7 Correct 8 ms 12216 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 5 ms 12280 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 296 ms 16308 KB Output is correct
12 Incorrect 195 ms 15296 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 6 ms 12120 KB Output is correct
3 Correct 7 ms 12124 KB Output is correct
4 Correct 5 ms 12120 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 5 ms 12124 KB Output is correct
7 Correct 8 ms 12216 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 5 ms 12280 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 296 ms 16308 KB Output is correct
12 Incorrect 195 ms 15296 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 6 ms 12120 KB Output is correct
3 Correct 7 ms 12124 KB Output is correct
4 Correct 5 ms 12120 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 5 ms 12124 KB Output is correct
7 Correct 8 ms 12216 KB Output is correct
8 Correct 6 ms 12120 KB Output is correct
9 Correct 5 ms 12280 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 296 ms 16308 KB Output is correct
12 Incorrect 195 ms 15296 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12124 KB Output is correct
2 Correct 6 ms 12024 KB Output is correct
3 Correct 11 ms 12188 KB Output is correct
4 Correct 7 ms 12124 KB Output is correct
5 Correct 6 ms 12124 KB Output is correct
6 Correct 6 ms 12136 KB Output is correct
7 Correct 10 ms 12124 KB Output is correct
8 Correct 8 ms 12120 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 6 ms 12124 KB Output is correct
11 Correct 6 ms 12124 KB Output is correct
12 Correct 5 ms 12124 KB Output is correct
13 Correct 8 ms 12444 KB Output is correct
14 Correct 7 ms 12376 KB Output is correct
15 Incorrect 9 ms 12124 KB Output isn't correct
16 Halted 0 ms 0 KB -