CF1476G.Minimum Difference

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer array aa of size nn.

You have to perform mm queries. Each query has one of two types:

  • "11 ll rr kk" — calculate the minimum value difdif such that there are exist kk distinct integers x1,x2,…,xkx_1, x_2, \dots, x_k such that cnti>0cnt_i \gt 0 (for every i∈[1,k]i \in [1, k]) and ∣cnti−cntj∣≤dif|cnt_i - cnt_j| \le dif (for every i∈[1,k],j∈[1,k]i \in [1, k], j \in [1, k]), where cnticnt_i is the number of occurrences of xix_i in the subarray a[l..r]a[l..r]. If it is impossible to choose kk integers, report it;
  • "22 pp xx" — assign ap:=xa_{p} := x.

给你一个长度为 nn 的整数数组 aa。

你需要执行 mm 个查询。每个查询为以下两种类型之一:

  • “11 ll rr kk” —— 计算最小的值 difdif,使得存在 kk 个互不相同的整数 x1,x2,…,xkx_1, x_2, \dots, x_k,满足:对每个 i∈[1,k]i \in [1, k],cnti>0cnt_i > 0;且对任意 i,j∈[1,k]i, j \in [1, k],均有 ∣cnti−cntj∣≤dif|cnt_i - cnt_j| \le dif。其中 cnticnt_i 表示 xix_i 在子数组 a[l..r]a[l..r] 中的出现次数。若无法选出 kk 个这样的整数,则报告该情况;
  • “22 pp xx” —— 将 apa_{p} 赋值为 xx。

输入格式

The first line contains two integers nn and mm (1≤n,m≤1051 \le n, m \le 10^5) — the size of the array aa and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1051 \le a_i \le 10^5).

Next mm lines contain queries (one per line). Each query has one of two types:

  • "11 ll rr kk" (1≤l≤r≤n;1≤k≤1051 \le l \le r \le n; 1 \le k \le 10^5)
  • "22 pp xx" (1≤p≤n;1≤x≤1051 \le p \le n; 1 \le x \le 10^5).

It's guaranteed that there is at least one query of the first type.

第一行包含两个整数 nn 和 mm(1≤n,m≤1051 \le n, m \le 10^5)——分别表示数组 aa 的大小和查询的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1051 \le a_i \le 10^5)。

接下来的 mm 行每行包含一个查询。每个查询为以下两种类型之一:

  • “11 ll rr kk”(1≤l≤r≤n1 \le l \le r \le n;1≤k≤1051 \le k \le 10^5)
  • “22 pp xx”(1≤p≤n1 \le p \le n;1≤x≤1051 \le x \le 10^5)。

保证至少存在一个第一类查询。

输出格式

For each query of the first type, print the minimum value of difdif that satisfies all required conditions, or −1-1 if it is impossible to choose kk distinct integers.

对于每个第一类查询,输出满足所有要求条件的 difdif 的最小值;如果无法选出 kk 个互不相同的整数,则输出 −1-1。

输入输出样例

  • 输入#1

    12 11
    2 1 1 2 1 1 3 2 1 1 3 3
    1 2 10 3
    1 2 11 3
    2 7 2
    1 3 9 2
    1 1 12 1
    1 1 12 4
    2 12 4
    1 1 12 4
    2 1 5
    1 3 12 2
    1 1 4 3

    输出#1

    5
    4
    1
    0
    -1
    5
    0
    1

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

首页