This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define int long long
using namespace std;
#define li long long
#define ld long double
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define em emplace
#define ob pop_back
#define om pop
#define of pop_front
#define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); ++i)
#define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define bitc __builtin_popcountll
mt19937 rng(uint64_t(new char));
#define rand rng
#define endl '\n'
#define sp ' '
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void solve();
signed main() {
// #ifdef GIAPVU
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
// #endif
fastio;
int tc = 1;
cin >> tc;
fori(test, 1, tc) {
solve();
}
return 0;
}
#define int long long
const int inf = LLONG_MAX / 100ll, mod = 1000000007 ;
const int maxn = 1e6 + 5, itsize = maxn << 1, maxit = maxn << 3, mapping = maxn;
int n, m;
int vs[maxn]; int ptr = 0;
void toposort(int i, int len) {
vs[i] = 1;
if(i - m >= 0 and !vs[i - m]) {
toposort(i - m, len);
}
if(i + n <= len and !vs[i + n]) {
toposort(i + n, len);
}
vs[i] = ++ptr;
}
bool build(int len);
bool build(int len) {
fill(vs, vs + len + 1, 0); ptr = 0;
fori(i, 0, len) {
if(!vs[i]) toposort(i, len);
}
fori(i, 0, len) {
if(i - m >= 0 and vs[i] <= vs[i - m]) return 0;
if(i + n <= len and vs[i] <= vs[i + n]) return 0;
}
return 1;
}
void solve() {
cin >> n >> m;
int lo = 0, hi = n + m;
while(lo < hi) {
int mi = lo + hi + 1 >> 1;
// cout << "mi:" << mi << endl;
if(build(mi)) lo = mi;
else hi = mi - 1;
}
build(lo);
cout << lo << endl;
fori(i,1,lo) {
cout << vs[i] - vs[i - 1] << sp;
}
cout << endl;
}
Compilation message (stderr)
sequence.cpp: In function 'void solve()':
sequence.cpp:85:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int mi = lo + hi + 1 >> 1;
| ~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |