Codeforces Round 581 (Div. 2)
D2
Kirk and a Binary String (hard version)
Codeforces
2100
原题
← D1E →
翻译中…

The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.

翻译中…

Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions:

翻译中…
  • For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$;
  • The number of zeroes in $t$ is the maximum possible.
翻译中…

A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 \lt i_2 \lt \ldots \lt i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$.

翻译中…

If there are multiple substrings which satisfy the conditions, output any.

翻译中…

Input

翻译中…

The first line contains a binary string of length not more than $10^5$.

翻译中…

Output

翻译中…

Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.

翻译中…

Note

翻译中…

In the first example:

翻译中…
  • For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$;
  • For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$;
  • For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$;
  • For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$;
翻译中…

The second example is similar to the first one.

翻译中…

样例

Input #1
110
Output #1
010
InputCopy OutputCopy
Input #2
010
Output #2
010
InputCopy OutputCopy
Input #3
0001111
Output #3
0000000
InputCopy OutputCopy
Input #4
0111001100111011101000
Output #4
0011001100001011101000
InputCopy OutputCopy
题目信息
题号
1204D2
时间限制
1 s
内存限制
256 MB
标签
数据结构
贪心
数学
字符串

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