CF1764H.Doremy's Paint 2

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Doremy has nn buckets of paint which is represented by an array aa of length nn. Bucket ii contains paint with color aia_i. Initially, ai=ia_i=i.

Doremy has mm segments [li,ri][l_i,r_i] (1≤li≤ri≤n1 \le l_i \le r_i \le n). Each segment describes an operation. Operation ii is performed as follows:

  • For each jj such that li<j≤ril_i \lt j \leq r_i, set aj:=alia_j := a_{l_i}.

Doremy also selects an integer kk. She wants to know for each integer xx from 00 to m−1m-1, the number of distinct colors in the array after performing operations x mod m+1,(x+1) mod m+1,…,(x+k−1) mod m+1x \bmod m +1, (x+1) \bmod m + 1, \ldots, (x+k-1) \bmod m +1. Can you help her calculate these values? Note that for each xx individually we start from the initial array and perform only the given kk operations in the given order.

Doremy 有 nn 桶颜料,用一个长度为 nn 的数组 aa 表示。其中第 ii 桶颜料的颜色为 aia_i。初始时,ai=ia_i = i。

Doremy 还有 mm 个区间 [li,ri][l_i, r_i](满足 1≤li≤ri≤n1 \le l_i \le r_i \le n)。每个区间描述一次操作。第 ii 次操作的执行方式如下:

  • 对每个满足 li<j≤ril_i < j \leq r_i 的 jj,令 aj:=alia_j := a_{l_i}。

此外,Doremy 还选定一个整数 kk。她希望对每个从 00 到 m−1m-1 的整数 xx,计算在初始数组上依次执行操作 (x mod m)+1, (x+1) mod m+1, …, (x+k−1) mod m+1(x \bmod m) + 1,\ (x+1) \bmod m + 1,\ \ldots,\ (x+k-1) \bmod m + 1 后,数组中不同颜色的种类数。你能帮她算出这些值吗?注意:对每个 xx,我们均从初始数组出发,仅按给定顺序执行这 kk 次操作。

输入格式

The first line of input contains three integers nn, mm, and kk (1≤n,m≤2⋅1051\le n,m\le 2\cdot 10^5, 1≤k≤m1 \le k \le m) — the length of the array aa, the total number of operations, and the integer that Doremy selects.

The ii-th line of the following mm lines contains two integers lil_i, rir_i (1≤li≤ri≤n1\le l_i\le r_i\le n) — the bounds of the ii-th segment.

输入的第一行包含三个整数 nn、mm 和 kk(1≤n,m≤2⋅1051\le n,m\le 2\cdot 10^5,1≤k≤m1 \le k \le m)——分别表示数组 aa 的长度、操作总数以及 Doremy 所选择的整数。

接下来的 mm 行中,第 ii 行包含两个整数 lil_i、rir_i(1≤li≤ri≤n1\le l_i\le r_i\le n)——表示第 ii 个区间的左右端点。

输出格式

Output mm integers. The (x+1)(x+1)-th integer should be the number of distinct colors in the array if we start from the initial array and perform operations x mod m+1,(x+1) mod m+1,…,(x+k−1) mod m+1x \bmod m +1, (x+1) \bmod m + 1, \ldots, (x+k-1) \bmod m +1.

输出 mm 个整数。第 (x+1)(x+1) 个整数应为:从初始数组出发,依次执行操作 x mod m+1, (x+1) mod m+1, …, (x+k−1) mod m+1x \bmod m +1,\ (x+1) \bmod m + 1,\ \ldots,\ (x+k-1) \bmod m +1 后,数组中不同颜色的数量。

输入输出样例

  • 输入#1

    7 5 5
    3 5
    2 3
    4 6
    5 7
    1 2

    输出#1

    3 3 3 3 2
  • 输入#2

    10 9 4
    1 1
    2 3
    3 4
    7 9
    6 8
    5 7
    2 4
    9 10
    1 3

    输出#2

    6 6 7 6 5 5 7 7 7

说明/提示

In the first test case, the picture below shows the resulting array for the values of x=0,1,2x=0,1,2 respectively.

在第一个测试用例中,下图分别展示了 x=0,1,2x=0,1,2 时所得数组的结果。

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

首页