A15879 | Red-Blue Operations (Hard Version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The only difference between easy and hard versions is the maximum values of $n$ and $q$ .
You are given an array, consisting of $n$ integers. Initially, all elements are red.
You can apply the following operation to the array multiple times. During the $i$ -th operation, you select an element of the array; then:
- if the element is red, it increases by $i$ and becomes blue;
- if the element is blue, it decreases by $i$ and becomes red.
The operations are numbered from $1$ , i. e. during the first operation some element is changed by $1$ and so on.
You are asked $q$ queries of the following form:
- given an integer $k$ , what can the largest minimum in the array be if you apply exactly $k$ operations to it?
Note that the operations don't affect the array between queries, all queries are asked on the initial array $a$ .
You are given an array, consisting of $n$ integers. Initially, all elements are red.
You can apply the following operation to the array multiple times. During the $i$ -th operation, you select an element of the array; then:
- if the element is red, it increases by $i$ and becomes blue;
- if the element is blue, it decreases by $i$ and becomes red.
The operations are numbered from $1$ , i. e. during the first operation some element is changed by $1$ and so on.
You are asked $q$ queries of the following form:
- given an integer $k$ , what can the largest minimum in the array be if you apply exactly $k$ operations to it?
Note that the operations don't affect the array between queries, all queries are asked on the initial array $a$ .
输入格式
The first line contains two integers $n$ and $q$ ( $1 \le n, q \le 2 \cdot 10^5$ ) — the number of elements in the array and the number of queries.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ).
The third line contains $q$ integers $k_1, k_2, \dots, k_q$ ( $1 \le k_j \le 10^9$ ).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ).
The third line contains $q$ integers $k_1, k_2, \dots, k_q$ ( $1 \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 $k$ operations to it.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted