1527_Multi-keySorting

2022-5-16 18:17| 发布者: Hocassian| 查看: 59| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-2-89503887479700-Problem List-采集的数据-后羿采集器.html

Pro.ID

1527

Title

Multi-key Sorting

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=1527

AC

2

Submit

2

Ratio

100.00%

时间&空间限制

  • Time Limit: 12000/4000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    Consider a table with rows and columns. The columns are numbered from 1 to C. For simplicity's sake, the items in the table are strings consisting of lower case letters.

    1

    2

    3

    XX

     

    1

    2

    3

    XX

     

    1

    2

    3

    apple

    red

    sweet

     

    banana

    brown

    rotten

     

    apple

    green

    sour

    apple

    green

    sour

     

    apple

    green

    sour

     

    apple

    red

    sweet

    pear

    green

    sweet

     

    pear

    green

    sweet

     

    banana

    brown

    rotten

    banana

    yellow

    sweet

     

    apple

    red

    sweet

     

    banana

    yellow

    sweet

    banana

    brown

    rotten

     

    banana

    yellow

    sweet

     

    pear

    green

    sweet

    Table 1                           Table 2                               Table 3

    You are given the operation Sort(k) on such tables: Sort(k) sorts the rows of a table in the order of the values in column k (while the order of the columns does not change). The sort is stable, that is, rows that have equal values in column k, remain in their original order. For example, applying Sort(2) to Table 1 yields Table 2.

    We are interested in sequences of such sort operations. These operations are successively applied to the same table. For example, applying the sequence Sort(2); Sort(1) to Table 1 yields Table 3.

    Two sequences of sort operations are called equivalent if, for any table, they have the same effect. For example, Sort(2); Sort(2); Sort(1) is equivalent to Sort(2); Sort(1). However, it is not equivalent to Sort(1); Sort(2), because the effect on Table 1 is different.

    Task

    Given a sequence of sort operations, determine a shortest equivalent sequence.

    输入

    注意:输入包含多个测试数据。

    The first line of the input contains two integers, C and N. C (1 ≤ C ≤ 1 000 000 ) is the number of columns and N (1 ≤ N ≤ 3 000 000) is the number of sort operations. The second line contains N integers, ki (1 ≤ ki ≤ C). It defines the sequence of sort operations Sort(k1); ...; Sort(kN).

    输出

    Description

    Consider a table with rows and columns. The columns are numbered from 1 to C. For simplicity's sake, the items in the table are strings consisting of lower case letters.

    1

    2

    3

    XX

     

    1

    2

    3

    XX

     

    1

    2

    3

    apple

    red

    sweet

     

    banana

    brown

    rotten

     

    apple

    green

    sour

    apple

    green

    sour

     

    apple

    green

    sour

     

    apple

    red

    sweet

    pear

    green

    sweet

     

    pear

    green

    sweet

     

    banana

    brown

    rotten

    banana

    yellow

    sweet

     

    apple

    red

    sweet

     

    banana

    yellow

    sweet

    banana

    brown

    rotten

     

    banana

    yellow

    sweet

     

    pear

    green

    sweet

    Table 1                           Table 2                               Table 3

    You are given the operation Sort(k) on such tables: Sort(k) sorts the rows of a table in the order of the values in column k (while the order of the columns does not change). The sort is stable, that is, rows that have equal values in column k, remain in their original order. For example, applying Sort(2) to Table 1 yields Table 2.

    We are interested in sequences of such sort operations. These operations are successively applied to the same table. For example, applying the sequence Sort(2); Sort(1) to Table 1 yields Table 3.

    Two sequences of sort operations are called equivalent if, for any table, they have the same effect. For example, Sort(2); Sort(2); Sort(1) is equivalent to Sort(2); Sort(1). However, it is not equivalent to Sort(1); Sort(2), because the effect on Table 1 is different.

    Task

    Given a sequence of sort operations, determine a shortest equivalent sequence.

    Input

    注意:输入包含多个测试数据。

    The first line of the input contains two integers, C and N. C (1 ≤ C ≤ 1 000 000 ) is the number of columns and N (1 ≤ N ≤ 3 000 000) is the number of sort operations. The second line contains N integers, ki (1 ≤ ki ≤ C). It defines the sequence of sort operations Sort(k1); ...; Sort(kN).

    Output
    The first line of the output contains one integer, M, the length of the shortest sequence of sort operations equivalent to the input sequence (Subtask A). The second line contains exactly M integers, representing a shortest sequence (Subtask B). You can omit the second line if you solve only Subtask A.
    Sample Input
    4 6
    1 2 1 2 3 3
    Sample Output
    3
    1 2 3

    样例输入

    4 6
    1 2 1 2 3 3

    样例输出

    3
    1 2 3

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部