QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209658 | #7565. Harumachi Kaze | ucup-team1325 | WA | 663ms | 12184kb | C++17 | 4.7kb | 2023-10-10 16:25:37 | 2023-10-10 16:25:37 |
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 );
if( e <= 15 ) {
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 - 3 ) ) & 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] += 32768 - ( 1 << e );
}
} else {
for( int p = 0; p < 8; p ++ ) {
for( int t = 1; 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 - 3 ) ) & 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 );
}
}
#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 * 32768 ); build( build , 1 , 0 , 32767 );
}
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 , 32767 );
}
} ;
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 , sB ) ? sB : tA );
pA += ( 1 << f ) , sA = tA , oA = rs( oA ) , oB = ls( oB );
}
else {
if( !f ) return ( cmp( sA , tB ) ? tB : sA );
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( 32768 , 0 );
for( int i = 0; i <= n - 1; i ++ ) if( i + c[p] <= 32767 ) ap[i + c[p]] = a[i];
C[p] = segtree( ap , min( 32768 , n + c[p] ) );
}
for( int q = 0; q < 8; q ++ ) {
vector< ull > bq( 32768 , 0 );
for( int j = 0; j <= n - 1; j ++ ) if( j + d[q] <= 32767 ) bq[j + d[q]] = b[j];
D[q] = segtree( bq , min( 32768 , 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] <= 32767 ) 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] <= 32767 ) 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 == 32767 ) 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: 0
Wrong Answer
time: 663ms
memory: 12184kb
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:
wrong answer 2nd lines differ - expected: '1441151880758558720 1441151880758558720', found: '1152921504606846976 1152921504606846976'