#P8332. [ZJOI2022] 面条

[ZJOI2022] 面条

Background

Ren, Alice, Aya, and Yoko finally managed to prepare the first contest paper after many hardships. According to the original plan, Poor (Kanren) would prepare the second paper.

“Oh no, Kanren messaged me saying that after landing she was taken into quarantine for 30 days. She has no computer, so she can’t create the problem set,” Aya suddenly received the bad news.

“Then what do we do? We have no idea. We can’t just make it up!” Everyone panicked.

Looking at the date, there was only one week left before ZJOI.

To find out what happens next, please read the next episode.

Problem Description

Kujo Kanren is a girl who likes eating ramen.

One day she went to eat ramen, and she found that the ramen chef pulled for her a noodle of length nn. It is guaranteed that nn is even. Initially, the amount of seasoning at position ii is aia_i.

The following process is called one “ramen-pulling”:

  1. Fold the noodle in half. The noodle’s length becomes n2\frac{n}{2}. The amount of seasoning at position ii becomes the sum of the original seasonings at position ii and position ni+1n - i + 1. If the seasoning at position ii of the new noodle is bib_i, then bi=ai+ani+1b_i = a_i + a_{n - i + 1}.
  2. Stretch the noodle back to the original length nn. Each position becomes two positions, and the seasoning is split equally. If the seasoning at the current position ii is aia'_i, then $a'_i = \frac{1}{2} \times b_{\left\lceil \frac{i}{2} \right\rceil}$.

Now for a fixed xx, you need to answer qq queries. For each query, after the noodle undergoes kk “ramen-pulling” operations, find the amount of seasoning at position xx. You only need to output the result modulo 998244353998244353. Specifically, if the answer in lowest terms is ab\frac{a}{b}, output a×b1mod998244353a \times b^{-1} \bmod 998244353.

Input Format

The first line contains three positive integers test,T,seedtest, T, seed, representing the test point ID, the number of datasets, and the generation seed.

Then follow TT datasets, each consisting of two lines.

The first line contains four positive integers n,q,x,kmaxn, q, x, k_{\mathrm{max}}, representing the noodle length in this dataset, the number of queries, the queried position, and the upper bound for generating kk in the queries.

The second line contains nn non-negative integers. The ii-th integer aia_i represents the initial amount of seasoning at position ii on the noodle.

To avoid large input and output, the qq queries are generated by a generator we provide. Specifically, we provide a C++ code template noodle_template.cpp for contestants to use (see the appendix). We also give some explanations here:

First, we read from the input two 3232-bit integer variables test,T\mathit{test}, T, and one unsigned 6464-bit integer variable seed\mathit{seed}. Then we loop TT times, representing the TT datasets.

In each loop, we process one dataset. We first read three 3232-bit integer variables n,q,xn, q, x, and one 6464-bit integer variable kmaxk_{\mathrm{max}}. Then we read nn 3232-bit integer variables into the array a1,,ana_1, \ldots, a_n.

Next is the part that generates qq queries. Each time we call the function rd(), passing seed\mathit{seed} by reference. We take the returned value (an unsigned 6464-bit integer) modulo kmaxk_{\mathrm{max}} as the query parameter kk. Note that seed\mathit{seed} will also be modified.

Output Format

Output TT lines, each line containing one integer representing the answer for that dataset. Specifically, suppose the dataset has qq queries, and let the answer to the ii-th query be Ansi\mathrm{Ans}_i. You need to output i=1q(Ansii)\bigoplus_{i = 1}^q (\mathrm{Ans}_i \cdot i). Note that you do not need to take modulo here. \bigoplus denotes the bitwise XOR operator.

0 2 13
4 2 1 3
1 4 2 3
6 2 3 3
6 2 5 3 1 4

5
499122191

见附件中的 noodle/noodle_ex2.in
见附件中的 noodle/noodle_ex2.ans

Hint

[Sample Explanation #1]

In the first dataset, the initial {ai}\{ a_i \} is {1,4,2,3}\{ 1, 4, 2, 3 \}.
After one operation it becomes {2,2,3,3}\{ 2, 2, 3, 3 \}.
After two operations it becomes $\left\{ \frac{5}{2}, \frac{5}{2}, \frac{5}{2}, \frac{5}{2} \right\}$.

The generated queries are:
Queried position: x=1x = 1;
The first query: k=0k = 0, ax=1a_x = 1;
The second query: k=1k = 1, ax=2a_x = 2;
So the answer is (1×1)(2×2)=41=5(1 \times 1) \oplus (2 \times 2) = 4 \oplus 1 = 5.

In the second dataset, the initial {ai}\{ a_i \} is {6,2,5,3,1,4}\{ 6, 2, 5, 3, 1, 4 \}.
After one operation it becomes $\left\{ 5, 5, \frac{3}{2}, \frac{3}{2}, 4, 4 \right\}$.
After two operations it becomes $\left\{ \frac{9}{2}, \frac{9}{2}, \frac{9}{2}, \frac{9}{2}, \frac{3}{2}, \frac{3}{2} \right\}$.

The generated queries are:
Queried position: x=3x = 3;
The first query: k=2k = 2, ax=92a_x = \frac{9}{2}, 92499122181(mod998244353)\frac{9}{2} \equiv 499122181 \pmod{998244353};
The second query: k=0k = 0, ax=5a_x = 5;
So the answer is $(499122181 \times 1) \oplus (5 \times 2) = 499122181 \oplus 10 = 499122191$.

[Constraints]

For all test points: T10T \le 10, n2×106\sum n \le 2 \times {10}^6, q5×107\sum q \le 5 \times {10}^7, kmax1018k_{\mathrm{max}} \le {10}^{18}, 1xn1 \le x \le n, 0ai<9982443530 \le a_i < 998244353, 0seed26010 \le \mathit{seed} \le 2^{60} - 1, and nn is even.

Note that for the sample, the test point ID test\mathit{test} is 00.

The specific limits for each test point are shown in the table below:

Test Point ID n\sum n \le q\sum q \le kmaxk_{\mathrm{max}} \le Special Constraint
11 500500 None
22 2×1062 \times {10}^6 1010
33 1018{10}^{18} n=2kn = 2^k
44 5050 None
565 \sim 6 150150
77 2×1062 \times {10}^6 n=98304n = 98304
898 \sim 9 500500 None
101110 \sim 11 5×1035 \times {10}^3 2×1062 \times {10}^6
121312 \sim 13 2×1062 \times {10}^6 5050
141614 \sim 16 106{10}^6 105{10}^5
171817 \sim 18 2×1062 \times {10}^6 2×1072 \times {10}^7
192019 \sim 20 5×1075 \times {10}^7

[Appendix]

#include <bits/stdc++.h>
using namespace std;

unsigned long long rd (unsigned long long &x) {
	x ^= (x << 13);
	x ^= (x >> 7);
	x ^= (x << 17);
	return x;
}

int main () {
	int test, T;
	unsigned long long seed;
	scanf("%d%d%llu", &test, &T, &seed);
	for (int Case = 1; Case <= T; Case ++) {
		int n, q, x;
		long long k_max;
		scanf("%d%d%d%lld", &n, &q, &x, &k_max);
		vector<int> a(n + 1);
		for (int i = 1; i <= n; i ++) {
			scanf("%d", &a[i]);
		}
		for (int i = 1; i <= q; i ++) {
			long long k = rd(seed) % k_max;
			/∗
			Code your solution here.
			∗/
		}
	}
}

Translated by ChatGPT 5