Submission #965095

# Submission time Handle Problem Language Result Execution time Memory
965095 2024-04-18T06:30:05 Z angella Team Contest (JOI22_team) C++17
100 / 100
789 ms 25524 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 != 0 && maxi > a[2][it]) 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();
}

mt19937 rng(time(0));

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

	cin>>n;
    //n = 4;
    for(int i=1; i<=n; i++) {
        for(int j=0; j<3; j++) {
            //a[j][i] = rng()%6+1;
            cin>>a[j][i];
            //cout<<a[j][i]<<' ';
            comp[j].pb(a[j][i]);
        }
        //cout<<endl;
    }
    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();

    // int res = 0;
    // for(int i=1;i<=n;i++) {
    //     for(int j=1;j<=n;j++) {
    //         for(int k=1;k<=n;k++) {
    //             if(i==j||i==k||j==k) continue;
    //             if(a[0][i]<=max(a[0][j],a[0][k])) continue;
    //             if(a[1][j]<=max(a[1][i],a[1][k])) continue;
    //             if(a[2][k]<=max(a[2][j],a[2][i])) continue;
    //             res=max(res, a[0][i]+a[1][j]+a[2][k]);
    //         }
    //     }
    // }

    // cout<<res<<' '<<ans<<endl;

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

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14936 KB Output is correct
3 Correct 4 ms 14936 KB Output is correct
4 Correct 6 ms 14940 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 15196 KB Output is correct
10 Correct 6 ms 14940 KB Output is correct
11 Correct 5 ms 14992 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 5 ms 14940 KB Output is correct
14 Correct 5 ms 15028 KB Output is correct
15 Correct 5 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 5 ms 14940 KB Output is correct
18 Correct 5 ms 14984 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 5 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 6 ms 14940 KB Output is correct
23 Correct 5 ms 14936 KB Output is correct
24 Correct 5 ms 14936 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14936 KB Output is correct
3 Correct 4 ms 14936 KB Output is correct
4 Correct 6 ms 14940 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 15196 KB Output is correct
10 Correct 6 ms 14940 KB Output is correct
11 Correct 5 ms 14992 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 5 ms 14940 KB Output is correct
14 Correct 5 ms 15028 KB Output is correct
15 Correct 5 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 5 ms 14940 KB Output is correct
18 Correct 5 ms 14984 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 5 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 6 ms 14940 KB Output is correct
23 Correct 5 ms 14936 KB Output is correct
24 Correct 5 ms 14936 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 21 ms 15128 KB Output is correct
27 Correct 17 ms 15224 KB Output is correct
28 Correct 16 ms 15236 KB Output is correct
29 Correct 15 ms 15196 KB Output is correct
30 Correct 12 ms 15192 KB Output is correct
31 Correct 15 ms 14940 KB Output is correct
32 Correct 13 ms 15008 KB Output is correct
33 Correct 15 ms 15196 KB Output is correct
34 Correct 15 ms 15192 KB Output is correct
35 Correct 6 ms 14940 KB Output is correct
36 Correct 8 ms 15040 KB Output is correct
37 Correct 14 ms 14940 KB Output is correct
38 Correct 12 ms 15148 KB Output is correct
39 Correct 10 ms 15060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14996 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14952 KB Output is correct
7 Correct 5 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 6 ms 14940 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 283 ms 18464 KB Output is correct
12 Correct 175 ms 17576 KB Output is correct
13 Correct 214 ms 18372 KB Output is correct
14 Correct 285 ms 19376 KB Output is correct
15 Correct 250 ms 19896 KB Output is correct
16 Correct 242 ms 19216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14996 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14952 KB Output is correct
7 Correct 5 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 6 ms 14940 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 283 ms 18464 KB Output is correct
12 Correct 175 ms 17576 KB Output is correct
13 Correct 214 ms 18372 KB Output is correct
14 Correct 285 ms 19376 KB Output is correct
15 Correct 250 ms 19896 KB Output is correct
16 Correct 242 ms 19216 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 5 ms 14940 KB Output is correct
21 Correct 8 ms 14940 KB Output is correct
22 Correct 327 ms 18540 KB Output is correct
23 Correct 305 ms 18524 KB Output is correct
24 Correct 222 ms 17960 KB Output is correct
25 Correct 287 ms 19384 KB Output is correct
26 Correct 248 ms 19896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14996 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14952 KB Output is correct
7 Correct 5 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 6 ms 14940 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 283 ms 18464 KB Output is correct
12 Correct 175 ms 17576 KB Output is correct
13 Correct 214 ms 18372 KB Output is correct
14 Correct 285 ms 19376 KB Output is correct
15 Correct 250 ms 19896 KB Output is correct
16 Correct 242 ms 19216 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 5 ms 14940 KB Output is correct
21 Correct 8 ms 14940 KB Output is correct
22 Correct 327 ms 18540 KB Output is correct
23 Correct 305 ms 18524 KB Output is correct
24 Correct 222 ms 17960 KB Output is correct
25 Correct 287 ms 19384 KB Output is correct
26 Correct 248 ms 19896 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 7 ms 15016 KB Output is correct
29 Correct 6 ms 14936 KB Output is correct
30 Correct 5 ms 14936 KB Output is correct
31 Correct 16 ms 15124 KB Output is correct
32 Correct 6 ms 15000 KB Output is correct
33 Correct 6 ms 14940 KB Output is correct
34 Correct 358 ms 19132 KB Output is correct
35 Correct 348 ms 19332 KB Output is correct
36 Correct 365 ms 19384 KB Output is correct
37 Correct 345 ms 20008 KB Output is correct
38 Correct 262 ms 20664 KB Output is correct
39 Correct 164 ms 17876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 5 ms 14996 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14952 KB Output is correct
7 Correct 5 ms 14940 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 6 ms 14940 KB Output is correct
10 Correct 4 ms 14936 KB Output is correct
11 Correct 283 ms 18464 KB Output is correct
12 Correct 175 ms 17576 KB Output is correct
13 Correct 214 ms 18372 KB Output is correct
14 Correct 285 ms 19376 KB Output is correct
15 Correct 250 ms 19896 KB Output is correct
16 Correct 242 ms 19216 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 5 ms 14940 KB Output is correct
21 Correct 8 ms 14940 KB Output is correct
22 Correct 327 ms 18540 KB Output is correct
23 Correct 305 ms 18524 KB Output is correct
24 Correct 222 ms 17960 KB Output is correct
25 Correct 287 ms 19384 KB Output is correct
26 Correct 248 ms 19896 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 7 ms 15016 KB Output is correct
29 Correct 6 ms 14936 KB Output is correct
30 Correct 5 ms 14936 KB Output is correct
31 Correct 16 ms 15124 KB Output is correct
32 Correct 6 ms 15000 KB Output is correct
33 Correct 6 ms 14940 KB Output is correct
34 Correct 358 ms 19132 KB Output is correct
35 Correct 348 ms 19332 KB Output is correct
36 Correct 365 ms 19384 KB Output is correct
37 Correct 345 ms 20008 KB Output is correct
38 Correct 262 ms 20664 KB Output is correct
39 Correct 164 ms 17876 KB Output is correct
40 Correct 14 ms 15200 KB Output is correct
41 Correct 15 ms 15092 KB Output is correct
42 Correct 17 ms 15152 KB Output is correct
43 Correct 13 ms 14940 KB Output is correct
44 Correct 476 ms 20156 KB Output is correct
45 Correct 463 ms 20408 KB Output is correct
46 Correct 503 ms 20192 KB Output is correct
47 Correct 424 ms 20412 KB Output is correct
48 Correct 278 ms 21284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14936 KB Output is correct
3 Correct 4 ms 14936 KB Output is correct
4 Correct 6 ms 14940 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 15196 KB Output is correct
10 Correct 6 ms 14940 KB Output is correct
11 Correct 5 ms 14992 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 5 ms 14940 KB Output is correct
14 Correct 5 ms 15028 KB Output is correct
15 Correct 5 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 5 ms 14940 KB Output is correct
18 Correct 5 ms 14984 KB Output is correct
19 Correct 5 ms 14936 KB Output is correct
20 Correct 5 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 6 ms 14940 KB Output is correct
23 Correct 5 ms 14936 KB Output is correct
24 Correct 5 ms 14936 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 21 ms 15128 KB Output is correct
27 Correct 17 ms 15224 KB Output is correct
28 Correct 16 ms 15236 KB Output is correct
29 Correct 15 ms 15196 KB Output is correct
30 Correct 12 ms 15192 KB Output is correct
31 Correct 15 ms 14940 KB Output is correct
32 Correct 13 ms 15008 KB Output is correct
33 Correct 15 ms 15196 KB Output is correct
34 Correct 15 ms 15192 KB Output is correct
35 Correct 6 ms 14940 KB Output is correct
36 Correct 8 ms 15040 KB Output is correct
37 Correct 14 ms 14940 KB Output is correct
38 Correct 12 ms 15148 KB Output is correct
39 Correct 10 ms 15060 KB Output is correct
40 Correct 4 ms 14940 KB Output is correct
41 Correct 5 ms 14996 KB Output is correct
42 Correct 4 ms 14940 KB Output is correct
43 Correct 4 ms 14940 KB Output is correct
44 Correct 4 ms 14940 KB Output is correct
45 Correct 4 ms 14952 KB Output is correct
46 Correct 5 ms 14940 KB Output is correct
47 Correct 4 ms 14936 KB Output is correct
48 Correct 6 ms 14940 KB Output is correct
49 Correct 4 ms 14936 KB Output is correct
50 Correct 283 ms 18464 KB Output is correct
51 Correct 175 ms 17576 KB Output is correct
52 Correct 214 ms 18372 KB Output is correct
53 Correct 285 ms 19376 KB Output is correct
54 Correct 250 ms 19896 KB Output is correct
55 Correct 242 ms 19216 KB Output is correct
56 Correct 4 ms 14936 KB Output is correct
57 Correct 4 ms 14940 KB Output is correct
58 Correct 4 ms 14940 KB Output is correct
59 Correct 5 ms 14940 KB Output is correct
60 Correct 8 ms 14940 KB Output is correct
61 Correct 327 ms 18540 KB Output is correct
62 Correct 305 ms 18524 KB Output is correct
63 Correct 222 ms 17960 KB Output is correct
64 Correct 287 ms 19384 KB Output is correct
65 Correct 248 ms 19896 KB Output is correct
66 Correct 5 ms 14940 KB Output is correct
67 Correct 7 ms 15016 KB Output is correct
68 Correct 6 ms 14936 KB Output is correct
69 Correct 5 ms 14936 KB Output is correct
70 Correct 16 ms 15124 KB Output is correct
71 Correct 6 ms 15000 KB Output is correct
72 Correct 6 ms 14940 KB Output is correct
73 Correct 358 ms 19132 KB Output is correct
74 Correct 348 ms 19332 KB Output is correct
75 Correct 365 ms 19384 KB Output is correct
76 Correct 345 ms 20008 KB Output is correct
77 Correct 262 ms 20664 KB Output is correct
78 Correct 164 ms 17876 KB Output is correct
79 Correct 14 ms 15200 KB Output is correct
80 Correct 15 ms 15092 KB Output is correct
81 Correct 17 ms 15152 KB Output is correct
82 Correct 13 ms 14940 KB Output is correct
83 Correct 476 ms 20156 KB Output is correct
84 Correct 463 ms 20408 KB Output is correct
85 Correct 503 ms 20192 KB Output is correct
86 Correct 424 ms 20412 KB Output is correct
87 Correct 278 ms 21284 KB Output is correct
88 Correct 789 ms 25524 KB Output is correct
89 Correct 596 ms 23572 KB Output is correct
90 Correct 664 ms 23824 KB Output is correct
91 Correct 556 ms 23224 KB Output is correct
92 Correct 550 ms 21152 KB Output is correct
93 Correct 608 ms 22476 KB Output is correct
94 Correct 541 ms 21816 KB Output is correct
95 Correct 302 ms 23608 KB Output is correct
96 Correct 522 ms 25348 KB Output is correct
97 Correct 262 ms 22200 KB Output is correct
98 Correct 328 ms 21696 KB Output is correct
99 Correct 383 ms 21900 KB Output is correct