QOJ.ac

QOJ

実行時間制限: 5.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#18374. 序列操作 1

統計

给定一个长度为 $n$ 且元素取值在 $[0, 2]$ 范围内的整数序列 $a$。

一次操作定义为:选择一个下标 $x \in [1, n - 2]$:

  • 令 $s = (a_x + a_{x+1} + a_{x+2}) \bmod 3$,然后同时将 $a_x, a_{x+1}, a_{x+2}$ 的值都修改为 $s$。

你需要进行若干次操作(可以不进行),以最大化序列 $a$ 中所有元素的和。此外,你必须给出一个合法的操作序列,其长度不能超过 $\lfloor \frac{5}{7}n \rfloor + 100$。

输入格式

本题有多组测试数据。

第一行包含一个整数 $T$ —— 测试数据的组数。

对于每组测试数据:

第一行包含一个整数 $n$ —— 序列 $a$ 的长度。

第二行包含 $n$ 个整数,其中第 $i$ 个整数为 $a_i$。

输出格式

对于每组测试数据:

第一行应包含两个整数 $s$ 和 $K$ —— 分别表示序列的最大和以及操作次数。你必须保证 $0 \le K \le \lfloor \frac{5}{7}n \rfloor + 100$。

第二行应包含 $K$ 个正整数,其中第 $i$ 个整数表示第 $i$ 次操作中选择的下标 $x$。

样例

输入样例 1

3
3
0 1 0
5
0 2 1 2 2
7
1 1 1 1 1 1 1

输出样例 1

3 1
1
10 4
2 2 3 1
14 5
1 3 4 5 1

数据范围

对于 $100\%$ 的数据,保证 $1 \le T \le 1000$,$\sum n \le 10^6$,$3 \le n \le 10^6$,$0 \le a_i \le 2$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.