CF1204D2.Kirk and a Binary String (hard version)

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ss (a string which consists of zeroes and ones) of length nn and he is asking you to find a binary string tt of the same length which satisfies the following conditions:

  • For any ll and rr (1≤l≤r≤n1 \leq l \leq r \leq n) the length of the longest non-decreasing subsequence of the substring slsl+1…srs_{l}s_{l+1} \ldots s_{r} is equal to the length of the longest non-decreasing subsequence of the substring tltl+1…trt_{l}t_{l+1} \ldots t_{r};
  • The number of zeroes in tt is the maximum possible.

A non-decreasing subsequence of a string pp is a sequence of indices i1,i2,…,iki_1, i_2, \ldots, i_k such that i1<i2<…<iki_1 \lt i_2 \lt \ldots \lt i_k and pi1≤pi2≤…≤pikp_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}. The length of the subsequence is kk.

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

简单版本与困难版本的唯一区别在于字符串的长度。如果你解决了本题,就可以对本题进行 Hack;但只有当你同时解决了本题和上一题时,才可以对上一题进行 Hack。

Kirk 有一个长度为 nn 的二进制字符串 ss(即仅由 0 和 1 组成的字符串),他请你找出一个同样长度的二进制字符串 tt,使其满足以下条件:

  • 对任意 ll 和 rr(1≤l≤r≤n1 \leq l \leq r \leq n),子串 slsl+1…srs_{l}s_{l+1} \ldots s_{r} 的最长非递减子序列的长度,等于子串 tltl+1…trt_{l}t_{l+1} \ldots t_{r} 的最长非递减子序列的长度;
  • tt 中 0 的个数尽可能多。

字符串 pp 的一个非递减子序列是指一组下标 i1,i2,…,iki_1, i_2, \ldots, i_k,满足 i1<i2<…<iki_1 \lt i_2 \lt \ldots \lt i_k 且 pi1≤pi2≤…≤pikp_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}。该子序列的长度为 kk。

若存在多个满足条件的字符串 tt,输出任意一个即可。

输入格式

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

第一行包含一个长度不超过 10510^5 的二进制字符串。

输出格式

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

输出一个满足上述条件的二进制字符串。如果存在多个这样的字符串,则输出其中任意一个即可。

输入输出样例

  • 输入#1

    110

    输出#1

    010
  • 输入#2

    010

    输出#2

    010
  • 输入#3

    0001111

    输出#3

    0000000
  • 输入#4

    0111001100111011101000

    输出#4

    0011001100001011101000

说明/提示

In the first example:

  • For the substrings of the length 11 the length of the longest non-decreasing subsequnce is 11;
  • For l=1,r=2l = 1, r = 2 the longest non-decreasing subsequnce of the substring s1s2s_{1}s_{2} is 1111 and the longest non-decreasing subsequnce of the substring t1t2t_{1}t_{2} is 0101;
  • For l=1,r=3l = 1, r = 3 the longest non-decreasing subsequnce of the substring s1s3s_{1}s_{3} is 1111 and the longest non-decreasing subsequnce of the substring t1t3t_{1}t_{3} is 0000;
  • For l=2,r=3l = 2, r = 3 the longest non-decreasing subsequnce of the substring s2s3s_{2}s_{3} is 11 and the longest non-decreasing subsequnce of the substring t2t3t_{2}t_{3} is 11;

The second example is similar to the first one.

在第一个例子中:

  • 对于长度为 11 的子串,最长非递减子序列的长度为 11;
  • 当 l=1,r=2l = 1, r = 2 时,子串 s1s2s_{1}s_{2} 的最长非递减子序列为 1111,子串 t1t2t_{1}t_{2} 的最长非递减子序列为 0101;
  • 当 l=1,r=3l = 1, r = 3 时,子串 s1s3s_{1}s_{3} 的最长非递减子序列为 1111,子串 t1t3t_{1}t_{3} 的最长非递减子序列为 0000;
  • 当 l=2,r=3l = 2, r = 3 时,子串 s2s3s_{2}s_{3} 的最长非递减子序列为 11,子串 t2t3t_{2}t_{3} 的最长非递减子序列为 11;

第二个例子与第一个例子类似。

输入解题思路,AI测评打分。不知道怎么写?

首页