CF1476G.Minimum Difference
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer array a of size n.
You have to perform m queries. Each query has one of two types:
- "1 l r k" — calculate the minimum value dif such that there are exist k distinct integers x1,x2,…,xk such that cnti>0 (for every i∈[1,k]) and ∣cnti−cntj∣≤dif (for every i∈[1,k],j∈[1,k]), where cnti is the number of occurrences of xi in the subarray a[l..r]. If it is impossible to choose k integers, report it;
- "2 p x" — assign ap:=x.
给你一个长度为 n 的整数数组 a。
你需要执行 m 个查询。每个查询为以下两种类型之一:
- “1 l r k” —— 计算最小的值 dif,使得存在 k 个互不相同的整数 x1,x2,…,xk,满足:对每个 i∈[1,k],cnti>0;且对任意 i,j∈[1,k],均有 ∣cnti−cntj∣≤dif。其中 cnti 表示 xi 在子数组 a[l..r] 中的出现次数。若无法选出 k 个这样的整数,则报告该情况;
- “2 p x” —— 将 ap 赋值为 x。
输入格式
The first line contains two integers n and m (1≤n,m≤105) — the size of the array a and the number of queries.
The second line contains n integers a1,a2,…,an (1≤ai≤105).
Next m lines contain queries (one per line). Each query has one of two types:
- "1 l r k" (1≤l≤r≤n;1≤k≤105)
- "2 p x" (1≤p≤n;1≤x≤105).
It's guaranteed that there is at least one query of the first type.
第一行包含两个整数 n 和 m(1≤n,m≤105)——分别表示数组 a 的大小和查询的数量。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤105)。
接下来的 m 行每行包含一个查询。每个查询为以下两种类型之一:
- “1 l r k”(1≤l≤r≤n;1≤k≤105)
- “2 p x”(1≤p≤n;1≤x≤105)。
保证至少存在一个第一类查询。
输出格式
For each query of the first type, print the minimum value of dif that satisfies all required conditions, or −1 if it is impossible to choose k distinct integers.
对于每个第一类查询,输出满足所有要求条件的 dif 的最小值;如果无法选出 k 个互不相同的整数,则输出 −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测评打分。不知道怎么写?