CF1552E.Colors and Intervals

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The numbers 1, 2, …, n⋅k1, \, 2, \, \dots, \, n \cdot k are colored with nn colors. These colors are indexed by 1, 2, …, n1, \, 2, \, \dots, \, n. For each 1≤i≤n1 \le i \le n, there are exactly kk numbers colored with color ii.

Let [a, b][a, \, b] denote the interval of integers between aa and bb inclusive, that is, the set a, a+1, …, b{a, \, a + 1, \, \dots, \, b}. You must choose nn intervals [a1, b1], [a2, b2], …,[an, bn][a_1, \, b_1], \, [a_2, \, b_2], \, \dots, [a_n, \, b_n] such that:

  • for each 1≤i≤n1 \le i \le n, it holds 1≤ai<bi≤n⋅k1 \le a_i \lt b_i \le n \cdot k;
  • for each 1≤i≤n1 \le i \le n, the numbers aia_i and bib_i are colored with color ii;
  • each number 1≤x≤n⋅k1 \le x \le n \cdot k belongs to at most ⌈nk−1⌉\left\lceil \frac{n}{k - 1} \right\rceil intervals.

One can show that such a family of intervals always exists under the given constraints.

数字 1, 2, …, n⋅k1, \, 2, \, \dots, \, n \cdot k 被用 nn 种颜色染色。这些颜色编号为 1, 2, …, n1, \, 2, \, \dots, \, n。对每个 1≤i≤n1 \le i \le n,恰好有 kk 个数被染成颜色 ii。

记 [a, b][a, \, b] 为从 aa 到 bb(含端点)的所有整数构成的区间,即集合 {a, a+1, …, b}\{a, \, a + 1, \, \dots, \, b\}。你需要选出 nn 个区间 [a1, b1], [a2, b2], …,[an, bn][a_1, \, b_1], \, [a_2, \, b_2], \, \dots, [a_n, \, b_n],满足:

  • 对每个 1≤i≤n1 \le i \le n,均有 1≤ai<bi≤n⋅k1 \le a_i \lt b_i \le n \cdot k;
  • 对每个 1≤i≤n1 \le i \le n,数 aia_i 和 bib_i 均被染成颜色 ii;
  • 每个数 1≤x≤n⋅k1 \le x \le n \cdot k 至多属于 ⌈nk−1⌉\left\lceil \frac{n}{k - 1} \right\rceil 个区间。

可以证明:在给定约束条件下,这样的区间族总存在。

输入格式

The first line contains two integers nn and kk (1≤n≤1001 \le n \le 100, 2≤k≤1002 \le k \le 100) — the number of colors and the number of occurrences of each color.

The second line contains n⋅kn \cdot k integers c1, c2, …, cnkc_1, \, c_2, \, \dots, \, c_{nk} (1≤cj≤n1 \le c_j \le n), where cjc_j is the color of number jj. It is guaranteed that, for each 1≤i≤n1 \le i \le n, it holds cj=ic_j = i for exactly kk distinct indices jj.

第一行包含两个整数 nn 和 kk(1≤n≤1001 \le n \le 100,2≤k≤1002 \le k \le 100)—— 分别表示颜色种类数和每种颜色出现的次数。

第二行包含 n⋅kn \cdot k 个整数 c1, c2, …, cnkc_1, \, c_2, \, \dots, \, c_{nk}(1≤cj≤n1 \le c_j \le n),其中 cjc_j 表示编号为 jj 的数字的颜色。保证对于每个 1≤i≤n1 \le i \le n,恰好存在 kk 个不同的下标 jj 满足 cj=ic_j = i。

输出格式

Output nn lines. The ii-th line should contain the two integers aia_i and bib_i.

If there are multiple valid choices of the intervals, output any.

输出 nn 行。第 ii 行应包含两个整数 aia_i 和 bib_i。

如果存在多个满足条件的区间选择方案,输出任意一个即可。

输入输出样例

  • 输入#1

    4 3
    2 4 3 1 1 4 2 3 2 1 3 4

    输出#1

    4 5
    1 7
    8 11
    6 12
  • 输入#2

    1 2
    1 1

    输出#2

    1 2
  • 输入#3

    3 3
    3 1 2 3 2 1 2 1 3

    输出#3

    6 8
    3 7
    1 4
  • 输入#4

    2 3
    2 1 1 1 2 2

    输出#4

    2 3
    5 6

说明/提示

In the first sample, each number can be contained in at most ⌈43−1⌉=2\left\lceil \frac{4}{3 - 1} \right\rceil = 2 intervals. The output is described by the following picture:

In the second sample, the only interval to be chosen is forced to be [1, 2][1, \, 2], and each number is indeed contained in at most ⌈12−1⌉=1\left\lceil \frac{1}{2 - 1} \right\rceil = 1 interval.

In the third sample, each number can be contained in at most ⌈33−1⌉=2\left\lceil \frac{3}{3 - 1} \right\rceil = 2 intervals. The output is described by the following picture:

在第一个样例中,每个数最多可被 ⌈43−1⌉=2\left\lceil \frac{4}{3 - 1} \right\rceil = 2 个区间包含。输出由下图描述:

在第二个样例中,唯一可选的区间被迫为 [1, 2][1, \, 2],且每个数确实最多被 ⌈12−1⌉=1\left\lceil \frac{1}{2 - 1} \right\rceil = 1 个区间包含。

在第三个样例中,每个数最多可被 ⌈33−1⌉=2\left\lceil \frac{3}{3 - 1} \right\rceil = 2 个区间包含。输出由下图描述:

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

首页