CF1832D2.Red-Blue Operations (Hard Version)

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The only difference between easy and hard versions is the maximum values of nn and qq.

You are given an array, consisting of nn integers. Initially, all elements are red.

You can apply the following operation to the array multiple times. During the ii-th operation, you select an element of the array; then:

  • if the element is red, it increases by ii and becomes blue;
  • if the element is blue, it decreases by ii and becomes red.

The operations are numbered from 11, i. e. during the first operation some element is changed by 11 and so on.

You are asked qq queries of the following form:

  • given an integer kk, what can the largest minimum in the array be if you apply exactly kk operations to it?

Note that the operations don't affect the array between queries, all queries are asked on the initial array aa.

简单版本与困难版本的唯一区别在于 nn 和 qq 的最大值。

你被给定一个由 nn 个整数组成的数组。初始时,所有元素均为红色。

你可以对该数组多次执行如下操作:在第 ii 次操作中,你选择数组中的一个元素;然后:

  • 若该元素为红色,则其值增加 ii,并变为蓝色;
  • 若该元素为蓝色,则其值减少 ii,并变为红色。

操作从 11 开始编号,即第一次操作中某个元素被改变 11,依此类推。

你需要回答 qq 个如下形式的查询:

  • 给定整数 kk,若恰好对该数组执行 kk 次操作,数组中可能达到的最大最小值是多少?

注意:各次查询之间操作互不影响,所有查询均基于初始数组 aa 进行。

输入格式

The first line contains two integers nn and qq (1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5) — the number of elements in the array and the number of queries.

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

The third line contains qq integers k1,k2,…,kqk_1, k_2, \dots, k_q (1≤kj≤1091 \le k_j \le 10^9).

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5)—— 分别表示数组中元素的个数和查询的个数。

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

第三行包含 qq 个整数 k1,k2,…,kqk_1, k_2, \dots, k_q(1≤kj≤1091 \le k_j \le 10^9)。

输出格式

For each query, print a single integer — the largest minimum that the array can have after you apply exactly kk operations to it.

对于每个查询,输出一个整数——在对数组恰好执行 kk 次操作后,该数组所能达到的最大最小值。

输入输出样例

  • 输入#1

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

    输出#1

    3 4 5 6 7 8 8 10 8 12
  • 输入#2

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

    输出#2

    3 4 5 6 7 8 9 8 11 8
  • 输入#3

    2 5
    2 3
    10 6 8 1 3

    输出#3

    10 7 8 3 3

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

首页