#P16917. [JLCPC 2026] 题列序 1

    ID: 19235 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>吉林Special JudgeO2优化2026省赛/邀请赛

[JLCPC 2026] 题列序 1

Problem Description

You are given an integer sequence aa of length nn, where each value is in [0,2][0,2]. One operation is defined as follows:

  • Choose an index xx (1≤x≤n−21 \le x \le n - 2).
  • Let s=(ax+ax+1+ax+2) mod 3s=(a_x+a_{x+1}+a_{x+2}) \bmod 3, then change ax,ax+1,ax+2a_x, a_{x+1}, a_{x+2} all to ss at the same time.

You need to perform several operations (possibly none) to maximize the sum of all numbers in the sequence aa. At the same time, you must provide a valid operation plan whose number of operations does not exceed ⌊57n⌋+100\left\lfloor\dfrac{5}{7}n\right\rfloor+100. It can be proven that a plan satisfying the operation limit always exists.

Input Format

The first line contains an integer TT (1≤T≤10001 \le T \le 1000), the number of test cases. Then follow TT blocks, each describing one test case:

  • The first line contains an integer nn (3≤n≤1063 \le n \le 10^6), the length of the sequence aa.
  • The second line contains nn integers; the ii-th integer is aia_i (0≤ai≤20 \le a_i \le 2).

The data guarantees that ∑n≤106\sum n \le 10^6.

Output Format

For each test case:

  • The first line outputs two integers ss and KK, representing the maximum possible sequence sum and the number of operations in your plan. You must ensure $0 \le K \le \left\lfloor\dfrac{5}{7}n\right\rfloor + 100$.
  • The next line outputs KK positive integers; the ii-th integer is the chosen xx for the ii-th operation.
3
3
0 1 0
5
0 2 1 2 2
7
1 1 1 1 1 1 1
3 1
1
10 4
2 2 3 1
14 5
1 3 4 5 1

Hint

Translated by ChatGPT 5