#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 . It is guaranteed that is even. Initially, the amount of seasoning at position is .
The following process is called one “ramen-pulling”:
- Fold the noodle in half. The noodle’s length becomes . The amount of seasoning at position becomes the sum of the original seasonings at position and position . If the seasoning at position of the new noodle is , then .
- Stretch the noodle back to the original length . Each position becomes two positions, and the seasoning is split equally. If the seasoning at the current position is , then $a'_i = \frac{1}{2} \times b_{\left\lceil \frac{i}{2} \right\rceil}$.
Now for a fixed , you need to answer queries. For each query, after the noodle undergoes “ramen-pulling” operations, find the amount of seasoning at position . You only need to output the result modulo . Specifically, if the answer in lowest terms is , output .
Input Format
The first line contains three positive integers , representing the test point ID, the number of datasets, and the generation seed.
Then follow datasets, each consisting of two lines.
The first line contains four positive integers , representing the noodle length in this dataset, the number of queries, the queried position, and the upper bound for generating in the queries.
The second line contains non-negative integers. The -th integer represents the initial amount of seasoning at position on the noodle.
To avoid large input and output, the 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 -bit integer variables , and one unsigned -bit integer variable . Then we loop times, representing the datasets.
In each loop, we process one dataset. We first read three -bit integer variables , and one -bit integer variable . Then we read -bit integer variables into the array .
Next is the part that generates queries. Each time we call the function rd(), passing by reference. We take the returned value (an unsigned -bit integer) modulo as the query parameter . Note that will also be modified.
Output Format
Output lines, each line containing one integer representing the answer for that dataset. Specifically, suppose the dataset has queries, and let the answer to the -th query be . You need to output . Note that you do not need to take modulo here. 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 is .
After one operation it becomes .
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: ;
The first query: , ;
The second query: , ;
So the answer is .
In the second dataset, the initial is .
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: ;
The first query: , , ;
The second query: , ;
So the answer is $(499122181 \times 1) \oplus (5 \times 2) = 499122181 \oplus 10 = 499122191$.
[Constraints]
For all test points: , , , , , , , and is even.
Note that for the sample, the test point ID is .
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Constraint | |||
|---|---|---|---|---|
| None | ||||
| None | ||||
| None | ||||
[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