CF1758F.Decent Division

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A binary string is a string where every character is 0\texttt{0} or 1\texttt{1} . Call a binary string decent if it has an equal number of 0\texttt{0} s and 1\texttt{1} s.

Initially, you have an infinite binary string tt whose characters are all 0\texttt{0} s. You are given a sequence aa of nn updates, where aia_i indicates that the character at index aia_i will be flipped ( 01\texttt{0} \leftrightarrow \texttt{1} ). You need to keep and modify after each update a set SS of disjoint ranges such that:

  • for each range [l,r][l,r] , the substring tltrt_l \dots t_r is a decent binary string, and
  • for all indices ii such that ti=1t_i = \texttt{1} , there exists [l,r][l,r] in SS such that lirl \leq i \leq r .

You only need to output the ranges that are added to or removed from SS after each update. You can only add or remove ranges from SS at most 106\mathbf{10^6} times.

More formally, let SiS_i be the set of ranges after the ii -th update, where S0=S_0 = \varnothing (the empty set). Define XiX_i to be the set of ranges removed after update ii , and YiY_i to be the set of ranges added after update ii . Then for 1in1 \leq i \leq n , Si=(Si1Xi)YiS_i = (S_{i - 1} \setminus X_i) \cup Y_i . The following should hold for all 1in1 \leq i \leq n :

  • a,bSi,(ab)(ab=)\forall a,b \in S_i, (a \neq b) \rightarrow (a \cap b = \varnothing) ;
  • XiSi1X_i \subseteq S_{i - 1} ;
  • (Si1Xi)Yi=(S_{i-1} \setminus X_i) \cap Y_i = \varnothing ;
  • i=1n(Xi+Yi)106\displaystyle\sum_{i = 1}^n {(|X_i| + |Y_i|)} \leq 10^6 .

输入格式

The first line contains a single integer nn ( 1n21051 \leq n \leq 2 \cdot 10^5 ) — the number of updates.

The next nn lines each contain a single integer aia_i ( 1ai21051 \leq a_i \leq 2 \cdot 10^5 ) — the index of the ii -th update to the string.

输出格式

After the ii -th update, first output a single integer xix_i — the number of ranges to be removed from SS after update ii .

In the following xix_i lines, output two integers ll and rr ( 1l<r1061 \leq l < r \leq 10^6 ), which denotes that the range [l,r][l,r] should be removed from SS . Each of these ranges should be distinct and be part of SS .

In the next line, output a single integer yiy_i — the number of ranges to be added to SS after update ii .

In the following yiy_i lines, output two integers ll and rr ( 1l<r1061 \leq l < r \leq 10^6 ), which denotes that the range [l,r][l,r] should be added to SS . Each of these ranges should be distinct and not be part of SS .

The total number of removals and additions across all updates must not exceed 106\mathbf{10^6} .

After processing the removals and additions for each update, all the ranges in SS should be disjoint and cover all ones.

It can be proven that an answer always exists under these constraints.

输入输出样例

  • 输入#1

    5
    1
    6
    5
    5
    6

    输出#1

    0
    1
    1 2
    
    0
    1
    5 6
    
    1
    5 6
    2
    6 7
    4 5
    
    1
    4 5
    0
    
    1
    6 7
    0

说明/提示

Line breaks are provided in the sample only for the sake of clarity, and you don't need to print them in your output.

After the first update, the set of indices where ai=1a_i = 1 is {1}\{1\} . The interval [1,2][1, 2] is added, so S1={[1,2]}S_1 = \{[1, 2]\} , which has one 0\texttt{0} and one 1\texttt{1} .

After the second update, the set of indices where ai=1a_i = 1 is {1,6}\{1, 6\} . The interval [5,6][5, 6] is added, so S2={[1,2],[5,6]}S_2 = \{[1, 2], [5, 6]\} , each of which has one 0\texttt{0} and one 1\texttt{1} .

After the third update, the set of indices where ai=1a_i = 1 is {1,5,6}\{1, 5, 6\} . The interval [5,6][5, 6] is removed and the intervals [4,5][4, 5] and [6,7][6, 7] are added, so S3={[1,2],[4,5],[6,7]}S_3 = \{[1, 2], [4, 5], [6, 7]\} , each of which has one 0\texttt{0} and one 1\texttt{1} .

After the fourth update, the set of indices where ai=1a_i = 1 is {1,6}\{1, 6\} . The interval [4,5][4, 5] is removed, so S4={[1,2],[6,7]}S_4 = \{[1, 2], [6, 7]\} , each of which has one 0\texttt{0} and one 1\texttt{1} .

After the fifth update, the set of indices where ai=1a_i = 1 is {1}\{1\} . The interval [6,7][6, 7] is removed, so S5={[1,2]}S_5 = \{[1, 2]\} , which has one 0\texttt{0} and one 1\texttt{1} .

首页