QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#166655 | #7182. Very Sparse Table | ucup-team1325# | AC ✓ | 536ms | 9752kb | C++17 | 2.5kb | 2023-09-06 16:18:25 | 2023-09-06 16:18:25 |
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 ); }
void solve( ) {
int n; cin >> n;
vector< tuple< int , int , int > > eG;
auto adde = [&] ( int u , int v , int w ) -> void { assert( 0 <= u && u <= w && w <= v && v <= n ); eG.emplace_back( u , v , w ); } ;
auto solve = [&] ( auto solve , int L , int R ) -> void {
int t = R - L; if( t <= 3 ) return;
int s = sqrt( t );
for( int k = 0; ( s + 1 ) * k <= t; k ++ ) for( int i = s - 1; i >= 0; i -- ) if( ( s + 1 ) * k + s + 1 <= t ) adde( L + ( s + 1 ) * k + i , L + ( s + 1 ) * k + s + 1 , L + ( s + 1 ) * k + i + 1 );
for( int k = 0; ( s + 1 ) * k <= t; k ++ ) for( int i = 2; i <= s; i ++ ) if( ( s + 1 ) * k + i <= t ) adde( L + ( s + 1 ) * k , L + ( s + 1 ) * k + i , L + ( s + 1 ) * k + i - 1 );
for( int k = 0; ( s + 1 ) * k <= t; k ++ ) for( int l = k + 2; ( s + 1 ) * l <= t; l ++ ) if( ( s + 1 ) * l <= t ) adde( L + ( s + 1 ) * k , L + ( s + 1 ) * l , L + ( s + 1 ) * ( l - 1 ) );
for( int k = 0; ( s + 1 ) * k <= t; k ++ ) if( ( s + 1 ) * k + 1 <= t ) solve( solve , L + ( s + 1 ) * k + 1 , L + min( t , ( s + 1 ) * k + s ) );
} ;
solve( solve , 0 , n );
cout << ( int ) eG.size( ) << "\n"; for( auto [ u , v , w ] : eG ) cout << u << " " << w << " " << v << "\n"; cout.flush( );
int q; cin >> q;
while( q -- ) {
int u , v; cin >> u >> v;
if( v - u <= 3 ) { for( int i = u; i <= v; i ++ ) cout << i << " \n"[i == v]; cout.flush( ); continue; }
vector< int > ans;
auto dfs = [&] ( auto dfs , int L , int R ) -> void {
int t = R - L; if( t <= 3 ) return;
int s = sqrt( t );
if( ( u - L ) / ( s + 1 ) == ( v - L ) / ( s + 1 ) ) {
int k = ( u - L ) / ( s + 1 );
if( ( u - L ) % ( s + 1 ) != 0 ) dfs( dfs , L + ( s + 1 ) * k + 1 , L + min( t , ( s + 1 ) * k + s ) );
else ans = vector< int >{ u , v };
}
else {
int k = ( u - L ) / ( s + 1 ) , l = ( v - L ) / ( s + 1 );
ans = vector< int >{ u , L + ( s + 1 ) * k + s + 1 , L + ( s + 1 ) * l , v };
}
} ;
dfs( dfs , 0 , n ); ans.erase( unique( ans.begin( ) , ans.end( ) ) , ans.end( ) );
for( int i : ans ) cout << i << " \n"[i == ans.back( )]; 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: 0ms
memory: 3428kb
input:
9 45 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 4 3 5 3 6 3 7 3 8 3 9 4 5 4 6 4 7 4 8 4 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9
output:
11 2 3 4 1 2 4 0 1 4 6 7 8 5 6 8 4 5 8 0 1 2 0 2 3 4 5 6 4 6 7 0 4 8 0 1 0 1 2 0 1 2 3 0 4 0 4 5 0 4 6 0 4 7 0 4 8 0 4 8 9 1 2 1 2 3 1 2 3 4 1 4 5 1 4 6 1 4 7 1 4 8 1 4 8 9 2 3 2 3 4 2 3 4 5 2 4 6 2 4 7 2 4 8 2 4 8 9 3 4 3 4 5 3 4 5 6 3 4 7 3 4 8 3 4 8 9 4 5 4 5 6 4 5 6 7 4 8 4 8 9 5 6 5 6 7 5 6 7 8...
result:
ok edges: 11
Test #2:
score: 0
Accepted
time: 6ms
memory: 3444kb
input:
30 465 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 2 3 2 4 2 5 2 6...
output:
70 4 5 6 3 4 6 2 3 6 1 2 6 0 1 6 10 11 12 9 10 12 8 9 12 7 8 12 6 7 12 16 17 18 15 16 18 14 15 18 13 14 18 12 13 18 22 23 24 21 22 24 20 21 24 19 20 24 18 19 24 28 29 30 27 28 30 26 27 30 25 26 30 24 25 30 0 1 2 0 2 3 0 3 4 0 4 5 6 7 8 6 8 9 6 9 10 6 10 11 12 13 14 12 14 15 12 15 16 12 16 17 18 19 2...
result:
ok edges: 70
Test #3:
score: 0
Accepted
time: 536ms
memory: 3584kb
input:
736 200000 170 268 126 166 565 723 664 735 61 524 226 234 146 314 217 272 294 713 115 381 563 706 74 567 552 614 120 211 472 620 213 432 488 623 447 564 96 129 331 354 79 677 50 547 174 568 56 129 189 227 55 701 244 253 264 715 154 220 380 657 46 390 53 161 325 537 666 696 64 465 391 659 284 448 207...
output:
3147 26 27 28 25 26 28 24 25 28 23 24 28 22 23 28 21 22 28 20 21 28 19 20 28 18 19 28 17 18 28 16 17 28 15 16 28 14 15 28 13 14 28 12 13 28 11 12 28 10 11 28 9 10 28 8 9 28 7 8 28 6 7 28 5 6 28 4 5 28 3 4 28 2 3 28 1 2 28 0 1 28 54 55 56 53 54 56 52 53 56 51 52 56 50 51 56 49 50 56 48 49 56 47 48 56...
result:
ok edges: 3147
Test #4:
score: 0
Accepted
time: 521ms
memory: 9752kb
input:
65536 200000 51949 58727 7943 43298 6290 7369 41493 53070 24229 36675 28087 49947 11703 48217 19923 24739 2144 59777 53830 56793 13509 37211 2300 38595 27415 42879 24616 48531 58341 63327 20628 38407 48616 60290 7450 61685 37010 47595 22164 42732 19181 29850 35383 43587 39257 44397 19340 45183 34523...
output:
381480 255 256 257 254 255 257 253 254 257 252 253 257 251 252 257 250 251 257 249 250 257 248 249 257 247 248 257 246 247 257 245 246 257 244 245 257 243 244 257 242 243 257 241 242 257 240 241 257 239 240 257 238 239 257 237 238 257 236 237 257 235 236 257 234 235 257 233 234 257 232 233 257 231 2...
result:
ok edges: 381480
Test #5:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
0 0
output:
0
result:
ok edges: 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
1 1 0 1
output:
0 0 1
result:
ok edges: 0
Test #7:
score: 0
Accepted
time: 1ms
memory: 3404kb
input:
2 3 0 1 0 2 1 2
output:
0 0 1 0 1 2 1 2
result:
ok edges: 0
Test #8:
score: 0
Accepted
time: 0ms
memory: 3428kb
input:
3 6 0 1 0 2 0 3 1 2 1 3 2 3
output:
0 0 1 0 1 2 0 1 2 3 1 2 1 2 3 2 3
result:
ok edges: 0
Test #9:
score: 0
Accepted
time: 409ms
memory: 9568kb
input:
65535 200000 35006 46944 17075 57351 24605 50445 5938 60705 15221 40233 28599 38915 1132 35574 8555 31494 13644 35806 44940 55401 9503 59206 21011 26540 41156 62487 57510 64305 9254 25610 17301 47249 34083 49167 48018 64394 38855 62175 15464 22525 23728 60275 54028 63810 22711 53902 5984 48625 5838 ...
output:
381570 254 255 256 253 254 256 252 253 256 251 252 256 250 251 256 249 250 256 248 249 256 247 248 256 246 247 256 245 246 256 244 245 256 243 244 256 242 243 256 241 242 256 240 241 256 239 240 256 238 239 256 237 238 256 236 237 256 235 236 256 234 235 256 233 234 256 232 233 256 231 232 256 230 2...
result:
ok edges: 381570
Test #10:
score: 0
Accepted
time: 507ms
memory: 9244kb
input:
64800 200000 55124 62263 24992 39760 32262 37059 25987 42889 10413 64701 7223 43221 45810 63205 11437 29357 10814 52096 1154 36319 10730 54157 18473 26729 9152 23374 5426 12744 3502 37577 5559 37160 30503 62433 12426 47332 14933 62086 8781 21527 27180 53773 29658 46742 20592 61553 8337 27197 8024 38...
output:
378169 253 254 255 252 253 255 251 252 255 250 251 255 249 250 255 248 249 255 247 248 255 246 247 255 245 246 255 244 245 255 243 244 255 242 243 255 241 242 255 240 241 255 239 240 255 238 239 255 237 238 255 236 237 255 235 236 255 234 235 255 233 234 255 232 233 255 231 232 255 230 231 255 229 2...
result:
ok edges: 378169
Extra Test:
score: 0
Extra Test Passed