Codeforces Global Round 29 (Div. 1 + Div. 2)
I2
Longest Increasing Path (Hard Version)
Codeforces
3500
原题
← I1→
翻译中…

This is the hard version of the problem. The difference between the versions is that in this version the second test is $n=300\,000$. Hacks are not allowed in this problem.

翻译中…

Let's call an integer sequence $a_1, a_2, \ldots, a_n$ distance-convex if $|a_{i} - a_{i-1}| \lt |a_{i+1} - a_{i}|$ for every $1 \lt i \lt n$. In other words, if you jump through the points $a_1, a_2, \ldots, a_n$ in this order, each next jump is strictly longer than the previous one.

翻译中…

You are given two integers $n$ and $m$. Find a distance-convex sequence $a$ of length $n$ that contains at most $m$ distinct values. In terms of the jump sequence, that would mean that you need to make $(n-1)$ jumps of increasing lengths while visiting at most $m$ distinct points. $-10^{18} \le a_i \le 10^{18}$ should hold for all $1 \le i \le n$.

翻译中…

Input

翻译中…

Input consists of two integers $n$ and $m$.

翻译中…

There are only 2 tests for this problem.

翻译中…
  • $n = 8$, $m = 6$;
  • $n = 300\,000$, $m = 15\,000$.
翻译中…

It is guaranteed that an answer exists for both tests.

翻译中…

Hacks are not allowed in this problem.

翻译中…

Output

翻译中…

Print a distance-convex sequence $a_1, a_2, \ldots, a_n$ that contains at most $m$ distinct values. $-10^{18} \le a_i \le 10^{18}$ should hold for all $1 \le i \le n$.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…

The sequence $[1, 1, 3, 6, 10, 3, 11, 1]$ has length $n=8$ and contains $5$ different values, which is less than or equal to $m=6$. The differences between consecutive values are $0,2,3,4,7,8,10$, a strictly increasing sequence.

翻译中…

$[1, 1, 2, 4, 8, 16, 32, 1]$ would be another valid answer.

翻译中…

样例

Input #1
8 6
Output #1
1 1 3 6 10 3 11 1
InputCopy OutputCopy
题目信息
题号
2147I2
时间限制
2 s
内存限制
256 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。