CF1716E.Swap and Maximum Block
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of length 2n . The elements of the array are numbered from 1 to 2n .
You have to process q queries to this array. In the i -th query, you will be given an integer k ( 0≤k≤n−1 ). To process the query, you should do the following:
- for every i∈[1,2n−2k] in ascending order, do the following: if the i -th element was already swapped with some other element during this query, skip it; otherwise, swap ai and ai+2k ;
- after that, print the maximum sum over all contiguous subsegments of the array (including the empty subsegment).
For example, if the array a is [−3,5,−3,2,8,−20,6,−1] , and k=1 , the query is processed as follows:
- the 1 -st element wasn't swapped yet, so we swap it with the 3 -rd element;
- the 2 -nd element wasn't swapped yet, so we swap it with the 4 -th element;
- the 3 -rd element was swapped already;
- the 4 -th element was swapped already;
- the 5 -th element wasn't swapped yet, so we swap it with the 7 -th element;
- the 6 -th element wasn't swapped yet, so we swap it with the 8 -th element.
So, the array becomes [−3,2,−3,5,6,−1,8,−20] . The subsegment with the maximum sum is [5,6,−1,8] , and the answer to the query is 18 .
Note that the queries actually change the array, i. e. after a query is performed, the array does not return to its original state, and the next query will be applied to the modified array.
输入格式
The first line contains one integer n ( 1≤n≤18 ).
The second line contains 2n integers a1,a2,…,a2n ( −109≤ai≤109 ).
The third line contains one integer q ( 1≤q≤2⋅105 ).
Then q lines follow, the i -th of them contains one integer k ( 0≤k≤n−1 ) describing the i -th query.
输出格式
For each query, print one integer — the maximum sum over all contiguous subsegments of the array (including the empty subsegment) after processing the query.
输入输出样例
输入#1
3 -3 5 -3 2 8 -20 6 -1 3 1 0 1
输出#1
18 8 13
说明/提示
Transformation of the array in the example: [−3,5,−3,2,8,−20,6,−1]→[−3,2,−3,5,6,−1,8,−20]→[2,−3,5,−3,−1,6,−20,8]→[5,−3,2,−3,−20,8,−1,6] .