#P1339. 小熊的果篮(2021)
小熊的果篮(2021)
Description
小熊的水果店里摆放着一排 <math xmlns="http://www.w3.org/1998/Math/MathML">nn 个水果。每个水果只可能是苹果或桔子,从左到右依次用正整数 <math xmlns="http://www.w3.org/1998/Math/MathML">1, 2, \ldots, n1,2,…,n 编号。连续排在一起的同一种水果称为一个“块”。小熊要把这一排水果挑到若干个果篮里,具体方法是:每次都把每一个“块”中最左边的水果同时挑出,组成一个果篮。重复这一操作,直至水果用完。注意,每次挑完一个果篮后,“块”可能会发生变化。比如两个苹果“块”之间的唯一桔子被挑走后,两个苹果“块”就变成了一个“块”。请帮小熊计算每个果篮里包含的水果。Input Format
第一行,包含一个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML">nn,表示水果的数量。
第二行,包含 <math xmlns="http://www.w3.org/1998/Math/MathML">nn 个空格分隔的整数,其中第 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 个数表示编号为 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 的水果的种类,<math xmlns="http://www.w3.org/1998/Math/MathML">11 代表苹果,<math xmlns="http://www.w3.org/1998/Math/MathML">00 代表桔子。
Output Format
输出若干行。
第 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 行表示第 <math xmlns="http://www.w3.org/1998/Math/MathML">ii 次挑出的水果组成的果篮。从小到大排序输出该果篮中所有水果的编号,每两个编号之间用一个空格分隔。
【输入 #1】
12
1 1 0 0 1 1 1 0 1 1 0 0
【输出 #1】
1 3 5 8 9 11
2 4 6 12
7
10
【输入 #2】
20
1 1 1 1 0 0 0 1 1 1 0 0 1 0 1 1 0 0 0 0
【输出 #2】
1 5 8 11 13 14 15 17
2 6 9 12 16 18
3 7 10 19
4 20
Hint
【样例解释 #1】
这是第一组数据的样例说明。
所有水果一开始的情况是 <math xmlns="http://www.w3.org/1998/Math/MathML">[1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0][1,1,0,0,1,1,1,0,1,1,0,0],一共有 <math xmlns="http://www.w3.org/1998/Math/MathML">66 个块。
在第一次挑水果组成果篮的过程中,编号为 <math xmlns="http://www.w3.org/1998/Math/MathML">1, 3, 5, 8, 9, 111,3,5,8,9,11 的水果被挑了出来。
之后剩下的水果是 <math xmlns="http://www.w3.org/1998/Math/MathML">[1, 0, 1, 1, 1, 0][1,0,1,1,1,0],一共 <math xmlns="http://www.w3.org/1998/Math/MathML">44 个块。
在第二次挑水果组成果篮的过程中,编号为 <math xmlns="http://www.w3.org/1998/Math/MathML">2, 4, 6, 122,4,6,12 的水果被挑了出来。
之后剩下的水果是 <math xmlns="http://www.w3.org/1998/Math/MathML">[1, 1][1,1],只有 <math xmlns="http://www.w3.org/1998/Math/MathML">11 个块。
在第三次挑水果组成果篮的过程中,编号为 <math xmlns="http://www.w3.org/1998/Math/MathML">77 的水果被挑了出来。
最后剩下的水果是 <math xmlns="http://www.w3.org/1998/Math/MathML">[1][1],只有 <math xmlns="http://www.w3.org/1998/Math/MathML">11 个块。
在第四次挑水果组成果篮的过程中,编号为 <math xmlns="http://www.w3.org/1998/Math/MathML">1010 的水果被挑了出来。
【数据范围】
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">10 \%10% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n \le 5n≤5。
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">30 \%30% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n \le 1000n≤1000。
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">70 \%70% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">n \le 50000n≤50000。
对于 <math xmlns="http://www.w3.org/1998/Math/MathML">100 \%100% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">1 \le n \le 2 \times {10}^51≤n≤2×105。
【提示】
由于数据规模较大,建议 C/C++ 选手使用 scanf
和 printf
语句输入、输出。
Source
四阶相关
在下列比赛中: