QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#209690 | #7565. Harumachi Kaze | ucup-team1325 | AC ✓ | 1621ms | 12588kb | C++17 | 4.7kb | 2023-10-10 16:38:51 | 2023-10-10 16:38:52 |
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 ) { if( !x || !y ) return x + 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 = 14; 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;
}
详细
Test #1:
score: 100
Accepted
time: 10ms
memory: 11908kb
input:
2 3 2 288230376151711744 864691128455135232 1441151880758558720 2017612633061982208 2 3 1 2 2 2594073385365405696 2 3 1152921504606846976 1152921504606846976 1152921504606846976 1152921504606846976 1152921504606846976 1152921504606846976 1152921504606846976 1152921504606846976 3458764513820540928 34...
output:
A 288230376151711744 864691128455135232 A 288230376151711744 864691128455135232 A 288230376151711744 864691128455135232 A 288230376151711744 864691128455135232 A 288230376151711744 864691128455135232 A 288230376151711744 864691128455135232 A 288230376151711744 864691128455135232 A 288230376151711744...
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 11968kb
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 5188146770730811392 3170534137668829184 5188146770730811392 2882303761517117440 518814677073...
output:
A 2017612633061982208 864691128455135232 A 2882303761517117440 2305843009213693952 A 864691128455135232 2305843009213693952 A 2017612633061982208 3170534137668829184 A 2017612633061982208 864691128455135232 A 2882303761517117440 2305843009213693952 A 864691128455135232 2305843009213693952 A 20176126...
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 1558ms
memory: 12576kb
input:
16000 20000 14 12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...
output:
A 12381691541923575949 2314459967875656919 A 15240288079556723088 320873566057825844 A 14696151509799232868 16557653430916204485 A 1013209648229540810 17538037439317817183 A 11476444495745028170 14967174865083701448 A 104503013837806377 7996875287119178002 A 12807060867005885737 9097870086258639932 ...
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 1508ms
memory: 12432kb
input:
16000 20000 14 14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...
output:
A 14874916021093924522 12369740409537030379 A 6287256359015658845 823444916947643237 A 9794404142223058838 7110701275963302082 A 4526221239260804705 11449122367236060745 A 5269387146536217002 12271448617436014402 A 15975343606496865450 90583475564335341 A 16905105418186360920 17062418867362856344 A ...
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 1617ms
memory: 12520kb
input:
16000 20000 14 12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...
output:
A 12315377266285165767 11473010392351879640 A 7998004721169407057 9573065544888591349 A 6338135370229149344 17571070266057998406 A 8327463206443780344 16951550409690804427 A 9014132268830135915 1328673092737196637 A 6832269542425033155 10342805361567332552 A 6458953347879251687 18171566689294021260 ...
result:
ok 2 lines
Test #6:
score: 0
Accepted
time: 1385ms
memory: 12512kb
input:
16000 20000 14 12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...
output:
A 12381691541923575949 2314459967875656919 A 15240288079556723088 320873566057825844 A 14696151509799232868 16557653430916204485 A 1013209648229540810 17538037439317817183 A 11476444495745028170 14967174865083701448 A 104503013837806377 7996875287119178002 A 12807060867005885737 9097870086258639932 ...
result:
ok 2 lines
Test #7:
score: 0
Accepted
time: 1394ms
memory: 12512kb
input:
16000 20000 14 14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...
output:
A 14874916021093924522 12369740409537030379 A 6287256359015658845 823444916947643237 A 9794404142223058838 7110701275963302082 A 4526221239260804705 11449122367236060745 A 5269387146536217002 12271448617436014402 A 15975343606496865450 90583475564335341 A 16905105418186360920 17062418867362856344 A ...
result:
ok 2 lines
Test #8:
score: 0
Accepted
time: 1349ms
memory: 12488kb
input:
16000 20000 14 12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...
output:
A 12315377266285165767 11473010392351879640 A 7998004721169407057 9573065544888591349 A 6338135370229149344 17571070266057998406 A 8327463206443780344 16951550409690804427 A 9014132268830135915 1328673092737196637 A 6832269542425033155 10342805361567332552 A 6458953347879251687 18171566689294021260 ...
result:
ok 2 lines
Test #9:
score: 0
Accepted
time: 1524ms
memory: 12492kb
input:
16000 20000 14 12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...
output:
A 12381691541923575949 2314459967875656919 A 15240288079556723088 320873566057825844 A 14696151509799232868 16557653430916204485 A 1013209648229540810 17538037439317817183 A 11476444495745028170 14967174865083701448 A 104503013837806377 7996875287119178002 A 12807060867005885737 9097870086258639932 ...
result:
ok 2 lines
Test #10:
score: 0
Accepted
time: 1498ms
memory: 12588kb
input:
16000 20000 14 14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...
output:
A 14874916021093924522 12369740409537030379 A 6287256359015658845 823444916947643237 A 9794404142223058838 7110701275963302082 A 4526221239260804705 11449122367236060745 A 5269387146536217002 12271448617436014402 A 15975343606496865450 90583475564335341 A 16905105418186360920 17062418867362856344 A ...
result:
ok 2 lines
Test #11:
score: 0
Accepted
time: 1621ms
memory: 12496kb
input:
16000 20000 14 12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...
output:
A 12315377266285165767 11473010392351879640 A 7998004721169407057 9573065544888591349 A 6338135370229149344 17571070266057998406 A 8327463206443780344 16951550409690804427 A 9014132268830135915 1328673092737196637 A 6832269542425033155 10342805361567332552 A 6458953347879251687 18171566689294021260 ...
result:
ok 2 lines