#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
using namespace std;
const long long oo = 1000000000000000000;
long long int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, p[ 400001 ], used[ 400001 ], nn[ 400001 ], mm[ 400001 ];
vector <int> v[ 400001 ], ts, vv;
void dfs( int u ) {
used[ u ] = 1;
int to = i + n;
int too = i - m;
if ( used[ to ] == 1 ) {
ans = 1;
return;
}
if ( used[ too ] == 1 ) {
ans = 1;
return;
}
if ( to <= mid && !used[ to ] )
dfs1( to );
if ( too >= 0 && !used[ too ] )
dfs1( too );
used[ u ] = 2;
}
void dfs1( int u ) {
used[ u ] = 1;
int to = i + n;
int too = i - m;
if ( to <= mid && !used[ to ] )
dfs1( to );
if ( too >= 0 && !used[ too ] )
dfs1( too );
ts.push_back( u );
}
bool ok( int x ) {
for ( int i = 0; i <= x; i ++ ) {
used[ i ] = 0;
}
ans = 0;
for ( int i = 0; i <= x; i ++ ) {
if ( !used[ i ] )
dfs( i );
}
if ( ans )
return false;
if ( sum ) {
ts.clear();
for ( int i = 0; i <= x; i ++ ) {
p[ i ] = 0;
used[ i ] = 0;
}
for ( int i = 0; i<= x; i ++ ) {
if ( !used[ i ] )
dfs1( i );
}
num = 0;
for ( auto i : ts )
p[ i ] = ++num;
for ( int i = 1; i <= x; i ++ ) {
p[ i ] -= p[ 0 ];
}
p[ 0 ] = 0;
}
return true;
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
int l, r, mid;
while ( t -- ) {
cin >> n >> m;
mx = max( n, m );
l = mx - 1;
r = 400000;
sum = 0;
while ( r - l > 1 ) {
mid = ( r + l ) / 2;
if ( ok( mid ) )
l = mid;
else
r = mid - 1;
}
if ( ok( r ) ) {
sum = 1;
ok( r );
cout << r << "\n";
for ( int i = 1; i <= r; i ++ )
cout << p[ i ] - p[ i - 1 ] << " ";
}
else {
sum = 1;
ok( l );
cout << l << "\n";
for ( int i = 1; i <= l; i ++ )
cout << p[ i ] - p[ i - 1 ] << " ";
}
cout << "\n";
}
}
Compilation message
sequence.cpp: In function 'void dfs(int)':
sequence.cpp:50:11: error: 'i' was not declared in this scope
50 | int to = i + n;
| ^
sequence.cpp:60:13: error: 'mid' was not declared in this scope
60 | if ( to <= mid && !used[ to ] )
| ^~~
sequence.cpp:61:3: error: 'dfs1' was not declared in this scope; did you mean 'dfs'?
61 | dfs1( to );
| ^~~~
| dfs
sequence.cpp:63:3: error: 'dfs1' was not declared in this scope; did you mean 'dfs'?
63 | dfs1( too );
| ^~~~
| dfs
sequence.cpp: In function 'void dfs1(int)':
sequence.cpp:69:11: error: 'i' was not declared in this scope
69 | int to = i + n;
| ^
sequence.cpp:71:13: error: 'mid' was not declared in this scope
71 | if ( to <= mid && !used[ to ] )
| ^~~