Submission #573437

# Submission time Handle Problem Language Result Execution time Memory
573437 2022-06-06T15:32:28 Z chonka Team Contest (JOI22_team) C++
100 / 100
1709 ms 40620 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int MAXN = 150007 ;
const int BASE = 150133 ;
ll MOD[ 2 ] = { 1000000007 , 998244353 } ;
ll pw[ 2 ][ MAXN ] ;

int n ;

struct sex {
    int x , y , z ;
};
sex a[ MAXN ] ;
int pos_y[ MAXN ] ;
int pos_z[ MAXN ] ;

struct hsh {
    ll val[ 2 ] ;
    int cnt ;
    hsh ( ) { val[ 0 ] = val[ 1 ] = cnt = 0 ; }
    hsh ( int x ) {
        for ( int i : { 0 , 1 } ) {
            val[ i ] = ( x % MOD[ i ] ) ;
        }
        cnt = 1 ;
    }
};

hsh unite ( hsh p1 , hsh p2 ) {
    hsh ret ;
    ret.cnt = p1.cnt + p2.cnt ;
    for ( int i = 0 ; i < 2 ; ++ i ) {
        ret.val[ i ] = ( p1.val[ i ] * pw[ i ][ p2.cnt ] + p2.val[ i ] ) % MOD[ i ] ;
    }
    return ret ;
}

class Tree {
public :
    hsh tr[ 4 * MAXN ] ;
    int leaves[ MAXN ] ;
    void init ( int where , int IL , int IR ) {
        tr[ where ] = hsh ( ) ;
        if ( IL == IR ) { return ; }
        int mid = ( IL + IR ) / 2 ;
        init ( 2 * where , IL , mid ) ;
        init ( 2 * where + 1 , mid + 1 , IR ) ;
    }
    void update ( int where , int IL , int IR , int pos , int id , int nw ) {
        if ( IR < pos || pos < IL ) { return ; }
        if ( IL == IR ) {
            tr[ where ] = hsh ( id ) ;
            leaves[ pos ] = nw ;
            return ;
        }
        int mid = ( IL + IR ) / 2 ;
        if ( pos <= mid ) {
            update ( 2 * where , IL , mid , pos , id , nw ) ;
        }
        else {
            update ( 2 * where + 1 , mid + 1 , IR , pos , id , nw ) ;
        }
        tr[ where ] = unite ( tr[ 2 * where ] , tr[ 2 * where + 1 ] ) ;
    }
    hsh query ( int where , int IL , int IR , int cnt ) {
        if ( cnt <= 0 ) { return hsh ( ) ; }
        if ( tr[ where ].cnt <= cnt ) {
            return tr[ where ] ;
        }
        int mid = ( IL + IR ) / 2 ;
        hsh r = query ( 2 * where + 1 , mid + 1 , IR , cnt ) ;
        hsh l = query ( 2 * where , IL , mid , cnt - r.cnt ) ;
        return unite ( l , r ) ;
    }
    int get_kth ( int where , int IL , int IR , int cnt ) {
        if ( cnt <= 0 ) { return -1 ; }
        if ( IL == IR ) { return leaves[ IL ] ; }
        int mid = ( IL + IR ) / 2 ;
        if ( tr[ 2 * where + 1 ].cnt >= cnt ) {
            return get_kth ( 2 * where + 1 , mid + 1 , IR , cnt ) ;
        }
        else {
            return get_kth ( 2 * where , IL , mid , cnt - tr[ 2 * where + 1 ].cnt ) ;
        }
    }
};

Tree w_y , w_z ;

pair < pair < int , int > , int > srt[ MAXN ] ;

void input ( ) {
    cin >> n ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ].x >> a[ i ].y >> a[ i ].z ;
    }
    auto cmp = [ & ] ( sex p1 , sex p2 ) {
        return ( p1.x < p2.x ) ;
    };
    for ( int i : { 0 , 1 } ) {
        pw[ i ][ 0 ] = 1 ;
        for ( int j = 1 ; j <= n ; ++ j ) {
            pw[ i ][ j ] = ( pw[ i ][ j - 1 ] * BASE ) % MOD[ i ] ;
        }
    }
    sort ( a + 1 , a + n + 1 , cmp ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        srt[ i ] = { { a[ i ].y , a[ i ].z } , i } ;
    }
    sort ( srt + 1 , srt + n + 1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        pos_y[ srt[ i ].second ] = i ;
    }

    for ( int i = 1 ; i <= n ; ++ i ) {
        srt[ i ] = { { a[ i ].z , a[ i ].y } , i } ;
    }
    sort ( srt + 1 , srt + n + 1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        pos_z[ srt[ i ].second ] = i ;
    }
}

bool diff ( int cnt ) {
    hsh h_y = w_y.query ( 1 , 1 , n , cnt ) ;
    hsh h_z = w_z.query ( 1 , 1 , n , cnt ) ;
    if ( h_y.val[ 0 ] != h_z.val[ 0 ] ) { return true ; }
    if ( h_y.val[ 1 ] != h_z.val[ 1 ] ) { return true ; }
    if ( h_y.cnt != h_z.cnt ) { return true ; }
    return false ;
}

void solve ( ) {
    w_y.init ( 1 , 1 , n ) ;
    w_z.init ( 1 , 1 , n ) ;
    int ans = -1 ;
    int lst = 1 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        while ( a[ lst ].x < a[ i ].x ) {
            w_y.update ( 1 , 1 , n , pos_y[ lst ] , lst , a[ lst ].y ) ;
            w_z.update ( 1 , 1 , n , pos_z[ lst ] , lst , a[ lst ].z ) ;
            ++ lst ;
        }
        int l , r , mid ;
        l = 1 , r = w_y.tr[ 1 ].cnt ;
        if ( r >= 1 && diff ( r ) == true ) {
            while ( r - l > 3 ) {
                mid = ( l + r ) / 2 ;
                if ( diff ( mid ) == true ) { r = mid ; }
                else { l = mid + 1 ; }
            }
            while ( diff ( l ) == false ) { ++ l ; }
            int aux_y = w_y.get_kth ( 1 , 1 , n , l ) ;
            int aux_z = w_z.get_kth ( 1 , 1 , n , l ) ;
            if ( a[ i ].y < aux_y && a[ i ].z < aux_z ) {
                ans = max ( ans , a[ i ].x + aux_y + aux_z ) ;
            }
        }
    }
    cout << ans << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t ;
    /// cin >> t ;
    ///scanf ( "%d" , &t ) ;
    t = 1 ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28544 KB Output is correct
2 Correct 13 ms 28528 KB Output is correct
3 Correct 15 ms 28524 KB Output is correct
4 Correct 13 ms 28500 KB Output is correct
5 Correct 14 ms 28548 KB Output is correct
6 Correct 13 ms 28540 KB Output is correct
7 Correct 13 ms 28500 KB Output is correct
8 Correct 13 ms 28500 KB Output is correct
9 Correct 13 ms 28500 KB Output is correct
10 Correct 14 ms 28524 KB Output is correct
11 Correct 13 ms 28496 KB Output is correct
12 Correct 14 ms 28528 KB Output is correct
13 Correct 13 ms 28528 KB Output is correct
14 Correct 14 ms 28532 KB Output is correct
15 Correct 13 ms 28552 KB Output is correct
16 Correct 15 ms 28500 KB Output is correct
17 Correct 13 ms 28500 KB Output is correct
18 Correct 12 ms 28520 KB Output is correct
19 Correct 13 ms 28464 KB Output is correct
20 Correct 13 ms 28500 KB Output is correct
21 Correct 13 ms 28500 KB Output is correct
22 Correct 14 ms 28488 KB Output is correct
23 Correct 15 ms 28492 KB Output is correct
24 Correct 13 ms 28500 KB Output is correct
25 Correct 16 ms 28552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28544 KB Output is correct
2 Correct 13 ms 28528 KB Output is correct
3 Correct 15 ms 28524 KB Output is correct
4 Correct 13 ms 28500 KB Output is correct
5 Correct 14 ms 28548 KB Output is correct
6 Correct 13 ms 28540 KB Output is correct
7 Correct 13 ms 28500 KB Output is correct
8 Correct 13 ms 28500 KB Output is correct
9 Correct 13 ms 28500 KB Output is correct
10 Correct 14 ms 28524 KB Output is correct
11 Correct 13 ms 28496 KB Output is correct
12 Correct 14 ms 28528 KB Output is correct
13 Correct 13 ms 28528 KB Output is correct
14 Correct 14 ms 28532 KB Output is correct
15 Correct 13 ms 28552 KB Output is correct
16 Correct 15 ms 28500 KB Output is correct
17 Correct 13 ms 28500 KB Output is correct
18 Correct 12 ms 28520 KB Output is correct
19 Correct 13 ms 28464 KB Output is correct
20 Correct 13 ms 28500 KB Output is correct
21 Correct 13 ms 28500 KB Output is correct
22 Correct 14 ms 28488 KB Output is correct
23 Correct 15 ms 28492 KB Output is correct
24 Correct 13 ms 28500 KB Output is correct
25 Correct 16 ms 28552 KB Output is correct
26 Correct 31 ms 28848 KB Output is correct
27 Correct 31 ms 28848 KB Output is correct
28 Correct 31 ms 28852 KB Output is correct
29 Correct 35 ms 28756 KB Output is correct
30 Correct 24 ms 28656 KB Output is correct
31 Correct 31 ms 28756 KB Output is correct
32 Correct 29 ms 28824 KB Output is correct
33 Correct 17 ms 28824 KB Output is correct
34 Correct 16 ms 28848 KB Output is correct
35 Correct 13 ms 28500 KB Output is correct
36 Correct 19 ms 28616 KB Output is correct
37 Correct 16 ms 28756 KB Output is correct
38 Correct 35 ms 28776 KB Output is correct
39 Correct 20 ms 28532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 28652 KB Output is correct
2 Correct 13 ms 28524 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 13 ms 28524 KB Output is correct
5 Correct 13 ms 28500 KB Output is correct
6 Correct 13 ms 28500 KB Output is correct
7 Correct 13 ms 28464 KB Output is correct
8 Correct 14 ms 28520 KB Output is correct
9 Correct 12 ms 28500 KB Output is correct
10 Correct 12 ms 28500 KB Output is correct
11 Correct 1134 ms 37552 KB Output is correct
12 Correct 594 ms 34508 KB Output is correct
13 Correct 216 ms 36044 KB Output is correct
14 Correct 833 ms 37324 KB Output is correct
15 Correct 95 ms 36580 KB Output is correct
16 Correct 56 ms 36320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 28652 KB Output is correct
2 Correct 13 ms 28524 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 13 ms 28524 KB Output is correct
5 Correct 13 ms 28500 KB Output is correct
6 Correct 13 ms 28500 KB Output is correct
7 Correct 13 ms 28464 KB Output is correct
8 Correct 14 ms 28520 KB Output is correct
9 Correct 12 ms 28500 KB Output is correct
10 Correct 12 ms 28500 KB Output is correct
11 Correct 1134 ms 37552 KB Output is correct
12 Correct 594 ms 34508 KB Output is correct
13 Correct 216 ms 36044 KB Output is correct
14 Correct 833 ms 37324 KB Output is correct
15 Correct 95 ms 36580 KB Output is correct
16 Correct 56 ms 36320 KB Output is correct
17 Correct 13 ms 28444 KB Output is correct
18 Correct 14 ms 28500 KB Output is correct
19 Correct 12 ms 28428 KB Output is correct
20 Correct 14 ms 28492 KB Output is correct
21 Correct 19 ms 28660 KB Output is correct
22 Correct 1218 ms 37816 KB Output is correct
23 Correct 1290 ms 37652 KB Output is correct
24 Correct 920 ms 35312 KB Output is correct
25 Correct 1199 ms 37856 KB Output is correct
26 Correct 97 ms 36812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 28652 KB Output is correct
2 Correct 13 ms 28524 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 13 ms 28524 KB Output is correct
5 Correct 13 ms 28500 KB Output is correct
6 Correct 13 ms 28500 KB Output is correct
7 Correct 13 ms 28464 KB Output is correct
8 Correct 14 ms 28520 KB Output is correct
9 Correct 12 ms 28500 KB Output is correct
10 Correct 12 ms 28500 KB Output is correct
11 Correct 1134 ms 37552 KB Output is correct
12 Correct 594 ms 34508 KB Output is correct
13 Correct 216 ms 36044 KB Output is correct
14 Correct 833 ms 37324 KB Output is correct
15 Correct 95 ms 36580 KB Output is correct
16 Correct 56 ms 36320 KB Output is correct
17 Correct 13 ms 28444 KB Output is correct
18 Correct 14 ms 28500 KB Output is correct
19 Correct 12 ms 28428 KB Output is correct
20 Correct 14 ms 28492 KB Output is correct
21 Correct 19 ms 28660 KB Output is correct
22 Correct 1218 ms 37816 KB Output is correct
23 Correct 1290 ms 37652 KB Output is correct
24 Correct 920 ms 35312 KB Output is correct
25 Correct 1199 ms 37856 KB Output is correct
26 Correct 97 ms 36812 KB Output is correct
27 Correct 13 ms 28580 KB Output is correct
28 Correct 13 ms 28532 KB Output is correct
29 Correct 13 ms 28500 KB Output is correct
30 Correct 16 ms 28520 KB Output is correct
31 Correct 30 ms 28728 KB Output is correct
32 Correct 17 ms 28596 KB Output is correct
33 Correct 16 ms 28524 KB Output is correct
34 Correct 1178 ms 37860 KB Output is correct
35 Correct 1264 ms 37452 KB Output is correct
36 Correct 1440 ms 38204 KB Output is correct
37 Correct 1223 ms 38504 KB Output is correct
38 Correct 114 ms 37120 KB Output is correct
39 Correct 48 ms 33608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 28652 KB Output is correct
2 Correct 13 ms 28524 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 13 ms 28524 KB Output is correct
5 Correct 13 ms 28500 KB Output is correct
6 Correct 13 ms 28500 KB Output is correct
7 Correct 13 ms 28464 KB Output is correct
8 Correct 14 ms 28520 KB Output is correct
9 Correct 12 ms 28500 KB Output is correct
10 Correct 12 ms 28500 KB Output is correct
11 Correct 1134 ms 37552 KB Output is correct
12 Correct 594 ms 34508 KB Output is correct
13 Correct 216 ms 36044 KB Output is correct
14 Correct 833 ms 37324 KB Output is correct
15 Correct 95 ms 36580 KB Output is correct
16 Correct 56 ms 36320 KB Output is correct
17 Correct 13 ms 28444 KB Output is correct
18 Correct 14 ms 28500 KB Output is correct
19 Correct 12 ms 28428 KB Output is correct
20 Correct 14 ms 28492 KB Output is correct
21 Correct 19 ms 28660 KB Output is correct
22 Correct 1218 ms 37816 KB Output is correct
23 Correct 1290 ms 37652 KB Output is correct
24 Correct 920 ms 35312 KB Output is correct
25 Correct 1199 ms 37856 KB Output is correct
26 Correct 97 ms 36812 KB Output is correct
27 Correct 13 ms 28580 KB Output is correct
28 Correct 13 ms 28532 KB Output is correct
29 Correct 13 ms 28500 KB Output is correct
30 Correct 16 ms 28520 KB Output is correct
31 Correct 30 ms 28728 KB Output is correct
32 Correct 17 ms 28596 KB Output is correct
33 Correct 16 ms 28524 KB Output is correct
34 Correct 1178 ms 37860 KB Output is correct
35 Correct 1264 ms 37452 KB Output is correct
36 Correct 1440 ms 38204 KB Output is correct
37 Correct 1223 ms 38504 KB Output is correct
38 Correct 114 ms 37120 KB Output is correct
39 Correct 48 ms 33608 KB Output is correct
40 Correct 26 ms 28628 KB Output is correct
41 Correct 31 ms 28736 KB Output is correct
42 Correct 15 ms 28792 KB Output is correct
43 Correct 35 ms 28784 KB Output is correct
44 Correct 1235 ms 38768 KB Output is correct
45 Correct 1502 ms 38820 KB Output is correct
46 Correct 1469 ms 38736 KB Output is correct
47 Correct 1274 ms 38960 KB Output is correct
48 Correct 108 ms 37724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28544 KB Output is correct
2 Correct 13 ms 28528 KB Output is correct
3 Correct 15 ms 28524 KB Output is correct
4 Correct 13 ms 28500 KB Output is correct
5 Correct 14 ms 28548 KB Output is correct
6 Correct 13 ms 28540 KB Output is correct
7 Correct 13 ms 28500 KB Output is correct
8 Correct 13 ms 28500 KB Output is correct
9 Correct 13 ms 28500 KB Output is correct
10 Correct 14 ms 28524 KB Output is correct
11 Correct 13 ms 28496 KB Output is correct
12 Correct 14 ms 28528 KB Output is correct
13 Correct 13 ms 28528 KB Output is correct
14 Correct 14 ms 28532 KB Output is correct
15 Correct 13 ms 28552 KB Output is correct
16 Correct 15 ms 28500 KB Output is correct
17 Correct 13 ms 28500 KB Output is correct
18 Correct 12 ms 28520 KB Output is correct
19 Correct 13 ms 28464 KB Output is correct
20 Correct 13 ms 28500 KB Output is correct
21 Correct 13 ms 28500 KB Output is correct
22 Correct 14 ms 28488 KB Output is correct
23 Correct 15 ms 28492 KB Output is correct
24 Correct 13 ms 28500 KB Output is correct
25 Correct 16 ms 28552 KB Output is correct
26 Correct 31 ms 28848 KB Output is correct
27 Correct 31 ms 28848 KB Output is correct
28 Correct 31 ms 28852 KB Output is correct
29 Correct 35 ms 28756 KB Output is correct
30 Correct 24 ms 28656 KB Output is correct
31 Correct 31 ms 28756 KB Output is correct
32 Correct 29 ms 28824 KB Output is correct
33 Correct 17 ms 28824 KB Output is correct
34 Correct 16 ms 28848 KB Output is correct
35 Correct 13 ms 28500 KB Output is correct
36 Correct 19 ms 28616 KB Output is correct
37 Correct 16 ms 28756 KB Output is correct
38 Correct 35 ms 28776 KB Output is correct
39 Correct 20 ms 28532 KB Output is correct
40 Correct 13 ms 28652 KB Output is correct
41 Correct 13 ms 28524 KB Output is correct
42 Correct 15 ms 28464 KB Output is correct
43 Correct 13 ms 28524 KB Output is correct
44 Correct 13 ms 28500 KB Output is correct
45 Correct 13 ms 28500 KB Output is correct
46 Correct 13 ms 28464 KB Output is correct
47 Correct 14 ms 28520 KB Output is correct
48 Correct 12 ms 28500 KB Output is correct
49 Correct 12 ms 28500 KB Output is correct
50 Correct 1134 ms 37552 KB Output is correct
51 Correct 594 ms 34508 KB Output is correct
52 Correct 216 ms 36044 KB Output is correct
53 Correct 833 ms 37324 KB Output is correct
54 Correct 95 ms 36580 KB Output is correct
55 Correct 56 ms 36320 KB Output is correct
56 Correct 13 ms 28444 KB Output is correct
57 Correct 14 ms 28500 KB Output is correct
58 Correct 12 ms 28428 KB Output is correct
59 Correct 14 ms 28492 KB Output is correct
60 Correct 19 ms 28660 KB Output is correct
61 Correct 1218 ms 37816 KB Output is correct
62 Correct 1290 ms 37652 KB Output is correct
63 Correct 920 ms 35312 KB Output is correct
64 Correct 1199 ms 37856 KB Output is correct
65 Correct 97 ms 36812 KB Output is correct
66 Correct 13 ms 28580 KB Output is correct
67 Correct 13 ms 28532 KB Output is correct
68 Correct 13 ms 28500 KB Output is correct
69 Correct 16 ms 28520 KB Output is correct
70 Correct 30 ms 28728 KB Output is correct
71 Correct 17 ms 28596 KB Output is correct
72 Correct 16 ms 28524 KB Output is correct
73 Correct 1178 ms 37860 KB Output is correct
74 Correct 1264 ms 37452 KB Output is correct
75 Correct 1440 ms 38204 KB Output is correct
76 Correct 1223 ms 38504 KB Output is correct
77 Correct 114 ms 37120 KB Output is correct
78 Correct 48 ms 33608 KB Output is correct
79 Correct 26 ms 28628 KB Output is correct
80 Correct 31 ms 28736 KB Output is correct
81 Correct 15 ms 28792 KB Output is correct
82 Correct 35 ms 28784 KB Output is correct
83 Correct 1235 ms 38768 KB Output is correct
84 Correct 1502 ms 38820 KB Output is correct
85 Correct 1469 ms 38736 KB Output is correct
86 Correct 1274 ms 38960 KB Output is correct
87 Correct 108 ms 37724 KB Output is correct
88 Correct 1277 ms 40620 KB Output is correct
89 Correct 1520 ms 40356 KB Output is correct
90 Correct 1346 ms 40608 KB Output is correct
91 Correct 1563 ms 40576 KB Output is correct
92 Correct 1459 ms 39132 KB Output is correct
93 Correct 1517 ms 39472 KB Output is correct
94 Correct 1308 ms 39536 KB Output is correct
95 Correct 131 ms 39628 KB Output is correct
96 Correct 171 ms 40524 KB Output is correct
97 Correct 71 ms 39140 KB Output is correct
98 Correct 158 ms 39180 KB Output is correct
99 Correct 1709 ms 39312 KB Output is correct