QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209587 | #7565. Harumachi Kaze | ucup-team1325 | RE | 878ms | 20672kb | C++17 | 4.3kb | 2023-10-10 15:59:21 | 2023-10-10 15:59:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull;
const int inf = 1e9; const ll llnf = 4e18;
template< class Tp > void chkmax( Tp &x , Tp y ) { x = max( x , y ); }
template< class Tp > void chkmin( Tp &x , Tp y ) { x = min( x , y ); }
ull add( ull x , ull y ) { cout << "A " << x << " " << y << "\n"; cout.flush( ); ull z; cin >> z; return z; }
bool cmp( ull x , ull y ) { cout << "C " << x << " " << y << "\n"; cout.flush( ); ull z; cin >> z; return ( z == x ); }
void solve( ) {
int n , m , e; cin >> n >> m >> e;
vector< ull > a( n ); for( int i = 0; i <= n - 1; i ++ ) cin >> a[i];
vector< ull > b( n ); for( int j = 0; j <= n - 1; j ++ ) cin >> b[j];
vector< tuple< int , int , ull > > qry( m );
for( int _ = 0; _ < m; _ ++ ) {
int opt; cin >> opt;
if( opt == 1 ) { int t , i; ull x; cin >> t >> i >> x; i --; qry[_] = make_tuple( ( t == 1 ? 0 : 1 ) , i , x ); }
if( opt == 2 ) { int k; cin >> k; qry[_] = make_tuple( -1 , k , 0 ); }
}
vector< int > c( 8 ) , d( 8 );
for( int p = 0; p < 8; p ++ ) {
for( int t = 0; t <= 2; t ++ ) if( ( p >> t ) & 1 ) if( t <= e - 1 ) c[p] += ( 1 << t ) + ( 1 << ( e - t - 1 ) );
}
for( int q = 0; q < 8; q ++ ) {
for( int t = 3; t <= 5; t ++ ) if( ( q >> t ) & 1 ) if( t <= e - 1 ) d[q] += ( 1 << t ) + ( 1 << ( e - t - 1 ) );
for( int t = 6; t <= e - 7; t ++ ) d[q] += ( 1 << t );
d[q] += 65536 - ( 1 << e );
}
#define ls( o ) 2 * o
#define rs( o ) 2 * o + 1
struct segtree {
vector< ull > tree; int n;
void pushup( int o ) { tree[o] = add( tree[ls( o )] , tree[rs( o )] ); }
segtree( ) { }
segtree( vector< ull > a , int _n ) {
auto build = [&] ( auto build , int o , int L , int R ) -> void {
if( L == R ) return tree[o] = a[L] , void( );
else { int M = ( L + R ) / 2; build( build , ls( o ) , L , M ) , build( build , rs( o ) , M + 1 , R ); pushup( o ); }
} ; n = _n , tree = vector< ull >( 2 * 65536 ); build( build , 1 , 0 , 65535 );
}
void set( int i , ull ai ) {
auto dfs = [&] ( auto dfs , int o , int L , int R ) -> void {
if( L == i && R == i ) return tree[o] = ai , void( );
else { int M = ( L + R ) / 2; ( i <= M ) ? ( dfs( dfs , ls( o ) , L , M ) ) : ( dfs( dfs , rs( o ) , M + 1 , R ) ); pushup( o ); }
} ; dfs( dfs , 1 , 0 , 65535 );
}
} ;
auto getans = [&] ( const segtree &A , const segtree &B ) -> ull {
int oA = 1 , oB = 1; ull sA = 0 , sB = 0; int pA = 0 , pB = 0;
for( int f = 15; f >= 0; f -- ) {
ull tA = add( sA , A.tree[ls( oA )] ) , tB = add( sB , B.tree[ls( oB )] );
if( pB + ( 1 << f ) > B.n || ( pA + ( 1 << f ) <= A.n && cmp( tA , tB ) ) ) {
if( !f ) return ( cmp( tA , tB ) ? tB : tA );
pA += ( 1 << f ) , sA = tA , oA = rs( oA ) , oB = ls( oB );
}
else {
if( !f ) return ( cmp( tA , tB ) ? tB : tA );
pB += ( 1 << f ) , sB = tB , oA = ls( oA ) , oB = rs( oB );
}
}
} ;
vector< segtree > C( 8 ) , D( 8 );
for( int p = 0; p < 8; p ++ ) {
vector< ull > ap( 65536 , 0 );
for( int i = 0; i <= n - 1; i ++ ) if( i + c[p] <= 65535 ) ap[i + c[p]] = a[i];
C[p] = segtree( ap , min( 65536 , n + c[p] ) );
}
for( int q = 0; q < 8; q ++ ) {
vector< ull > bq( 65536 , 0 );
for( int j = 0; j <= n - 1; j ++ ) if( j + d[q] <= 65535 ) bq[j + d[q]] = b[j];
D[q] = segtree( bq , min( 65536 , n + d[q] ) );
}
vector< ull > ans;
for( int _ = 0; _ < m; _ ++ ) {
if( get< 0 >( qry[_] ) == 0 ) {
int i = get< 1 >( qry[_] ); ull ai = get< 2 >( qry[_] );
for( int p = 0; p < 8; p ++ ) if( i + c[p] <= 65535 ) C[p].set( i + c[p] , ai );
} else if( get< 0 >( qry[_] ) == 1 ) {
int j = get< 1 >( qry[_] ); ull bj = get< 2 >( qry[_] );
for( int q = 0; q < 8; q ++ ) if( j + d[q] <= 65535 ) D[q].set( j + d[q] , bj );
} else {
int k = get< 1 >( qry[_] ); bool find = false;
for( int p = 0; p < 8; p ++ ) for( int q = 0; q < 8; q ++ ) if( !find && c[p] + d[q] + k == 65535 ) find = true , ans.emplace_back( getans( C[p] , D[q] ) );
if( !find ) assert( 0 );
}
}
cout << "! " << ( int ) ans.size( ) << "\n";
for( ull res : ans ) cout << res << " "; cout << "\n";
cout.flush( );
}
int main( ) {
ios::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 );
int T = 1; while( T -- ) solve( ); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 878ms
memory: 20672kb
input:
2 3 2 288230376151711744 864691128455135232 1441151880758558720 2017612633061982208 2 3 1 2 2 2594073385365405696 2 3 1152921504606846976 0 1152921504606846976 0 0 0 1152921504606846976 0 0 0 0 0 0 0 1152921504606846976 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1152921504606846976 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
A 288230376151711744 864691128455135232 A 0 0 A 1152921504606846976 0 A 0 0 A 0 0 A 0 0 A 1152921504606846976 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 1152921504606846976 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 1152921504606846976 0 A 0 0 A ...
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
3 5 3 2017612633061982208 864691128455135232 2305843009213693952 1441151880758558720 2017612633061982208 288230376151711744 2 5 2 2 1 1 3 1729382256910270464 1 2 1 2017612633061982208 2 5 2882303761517117440 2305843009213693952 5188146770730811392 0 0 0 5188146770730811392 0 0 0 0 0 0 0 518814677073...
output:
A 2017612633061982208 864691128455135232 A 2305843009213693952 0 A 2882303761517117440 2305843009213693952 A 0 0 A 0 0 A 0 0 A 5188146770730811392 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 5188146770730811392 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A...