luogu#P4964. 绫小路的特别考试

    ID: 3982 远端评测题 3000ms 250MiB 尝试: 2 已通过: 1 难度: 8 上传者: 标签>贪心枚举排序深度优先搜索 DFS

绫小路的特别考试

Background

In this world, “victory” is everything. The process does not matter.
No matter how many sacrifices it takes. As long as I “win” in the end, that is enough.

Problem Description

A new special exam is coming. This time the exam content is cultural courses (wan e de), but the difference is that students are allowed to use walkie-talkies during the exam. However, the receiving range of a walkie-talkie is limited (each walkie-talkie can transmit infinitely far, but can only receive signals within its receiving range), so not all students can receive broadcasts from other students.

During the exam, there are nn students sitting in a row (numbered from left to right as 11 to nn). Ayanokoji sits at position cc. Each student has an ability value wiw_i. Ayanokoji has assigned each student a walkie-talkie with receiving range did_i.

Each student can directly solve all problems whose difficulty is not greater than their own ability value. Once a student solves a problem by their own ability, they will broadcast the solution to that problem. A student sitting at position ii with a walkie-talkie of receiving range did_i can receive broadcasts from all students in the range [idi, i+di][i-d_i,\ i+d_i]. If someone within this range has published the solution, then they will solve the problem too, and will also broadcast the solution.

Ayanokoji will ask you some questions: when a problem has difficulty xx, how many students will solve it? Since Ayanokoji wants to hide his true strength, he may modify his own ability value. These two types of operations are represented as follows:

  • 1 x1\ x: query how many students will solve a problem with difficulty xx.
  • 2 x2\ x: modify Ayanokoji's ability value to xx, i.e., set wcw_c to xx.

Formal description (equivalent to the above):

You are given two sequences w1..nw_{1..n} and d1..nd_{1..n} of length nn, and a position cc where wcw_c can be modified. There are two types of operations (a total of mm times):

  • 1 x1\ x indicates a query: let $f_i=\begin{cases}1\quad(w_i\ge x)\\1\quad(\exists\ j \in [i - d_i,\ i + d_i],\ f_j=1)\\ 0\quad(otherwise)\end{cases}$. Here the definition of fif_i refers to fjf_j, so f1..nf_{1..n} will keep updating until it can no longer be updated. The answer to this query is i=1nfi\sum\limits_{i=1}^nf_i.
  • 2 x2\ x indicates a modification: set wcw_c to xx.

Input Format

Because the data size is too large, to avoid slow input reading, the input is given using a pseudorandom number generator and is forced online.

It is recommended that you ignore the input format and directly use the data generator template provided below. Understanding the specific generation process is not necessary for you.

The first line contains three positive integers n, m, cn,\ m,\ c, representing the total number of students, the total number of operations, and Ayanokoji's position.

The second line contains five integers $\mathrm{seed},\ \mathrm{mind},\ \mathrm{maxd},\ \mathrm{mfq},\ k$.

Here mind, maxd\mathrm{mind},\ \mathrm{maxd} are only used to generate the initial d1..nd_{1..n}. The tt used later to adjust dpd_p may not be within the range [mind, maxd][\mathrm{mind},\ \mathrm{maxd}].

In the next kk lines, each line contains two integers p, tp,\ t, indicating that the receiving range of student pp's walkie-talkie (i.e., dpd_p) is adjusted to tt.

If a student's walkie-talkie receiving range is adjusted multiple times, the last adjustment takes effect.


Data generator template:

#include <cstdio>

unsigned long long seed;
int n, m, c, mfq, mind, maxd, k, w[2000001], d[2000001];

inline int randInt() { seed = 99999989 * seed + 1000000007; return seed >> 33; } 

void generate()
{
	// 在读入种子后生成初始的 w 数组和 d 数组.
    for (int i = 1; i <= n; i++) { w[i] = randInt() % n; }
    for (int i = 1; i <= n; i++) { d[i] = randInt() % (maxd - mind + 1) + mind; }
}

void getOperation(int lastans, int &opt, int &x)
{
    // 生成一次操作的参数 opt 和 x, lastans 表示上一次询问的答案, 初始值为 0.
    if ((0ll + randInt() + lastans) % mfq) { opt = 1; } else { opt = 2; }
    x = (0ll + randInt() + lastans) % n;
}

int main()
{
    scanf("%d %d %d", &n, &m, &c);
    scanf("%llu %d %d %d %d", &seed, &mind, &maxd, &mfq, &k);
    generate();
    for (int i = 1; i <= k; i++)
    {
        int p, t;
        scanf("%d %d", &p, &t);
        d[p] = t;
    }
    // 从这里开始,你可以使用生成的 w 数组和 d 数组.
    int lastans = 0, finalans = 0;
    for (int i = 1; i <= m; i++)
    {
        int opt, x;
        getOperation(lastans, opt, x);
        if (opt == 1)
        {
            // 在这里执行询问操作,并用答案的表达式替代下面的 ___.      
            finalans = (finalans * 233ll + ___) % 998244353;
            lastans = ___;
        }
        else
        {
            // 在这里执行修改操作.
        }
    }
    printf("%d\n", finalans);
    return 0;
}

Output Format

Let ansians_i denote the answer to the ii-th query (operation 11), and let $T_i=\begin{cases}(T_{i-1}\times 233+ans_i)\mod 998244353\quad(i\ge 1)\\0\quad(i=0)\end{cases}$.

Let qq be the number of queries (operation 11). You only need to output one integer TqT_q.

3 3 2
19720918 0 1 2 0
700
10 10 8
2102036 0 1 4 1
5 2
760521825
1000 1000 126
114321251 1 2 2 0
91977056

Hint

Variables you will need:

1cn2×1061\le c\le n\le 2\times 10^6, 1m2×1061\le m\le 2\times 10^6, 0wi, di, x<n0\le w_i,\ d_i,\ x<n.

Other variables used to generate the testdata:

1seed, mfq1091\le \mathrm{seed},\ \mathrm{mfq}\le 10^9, 0mindmaxd<n0\le \mathrm{mind}\le \mathrm{maxd}<n, 0k2×1050\le k\le 2\times 10^5, 1pn1\le p\le n, 0t<n0\le t<n.

Sample Explanation

Sample 1:

Generated ability values for the three students are w1..3={0, 1, 2}w_{1..3} = \{0,\ 1,\ 2\}, and the walkie-talkie receiving ranges are d1..3={1, 0, 1}d_{1..3} = \{1,\ 0,\ 1\}.

The first operation is 1 1, asking how many students can solve a problem of difficulty 11.

Ayanokoji (student 22) and student 33 can solve it independently (w21w_2 \ge 1, w31w_3 \ge 1). Although student 11 does not have enough ability, he can receive the solution broadcast by Ayanokoji through the walkie-talkie (2[1d1, 1+d1]2 \in [1 - d_1,\ 1 + d_1]), so he can solve it as well. Therefore ans1=3ans_1 = 3.

The second operation is 2 0, modifying Ayanokoji's (student 22) ability value to 00. Now w1..3={0, 0, 2}w_{1..3} = \{0,\ 0,\ 2\}.

The third operation is 1 1, asking again how many students can solve a problem of difficulty 11.

Only student 33 can solve it independently (w31w_3 \ge 1). However, neither student 11 nor Ayanokoji (student 22) can receive his broadcast solution (3[1d1, 1+d1]3 \notin [1 - d_1,\ 1 + d_1], 3[2d2, 2+d2]3 \notin [2 - d_2,\ 2 + d_2]), so they cannot solve it. Therefore ans2=1ans_2 = 1.

In summary, T1=ans1=3T_1 = ans_1 = 3, T2=3×T1+ans2=3×233+1=700T_2 = 3 \times T_1+ ans_2 = 3 \times 233 + 1 = 700. You only need to output 700700.

Sample 2:

Generated $w_{1..10} = \{1,\ 6,\ 6,\ 5,\ 3,\ 5,\ 2,\ 7,\ 9,\ 5\}$, $d_{1..10} =\{1,\ 1,\ 1,\ 1,\ 2,\ 0,\ 1,\ 0,\ 1,\ 1\}$.

The ten operations and their corresponding results are as follows:

1 6, query, ans1=9ans_1 = 9, T1=9T_1 = 9.

2 2, modification, w1..10w_{1..10} becomes {1, 6, 6, 5, 3, 5, 2, 2, 9, 5}\{1,\ 6,\ 6,\ 5,\ 3,\ 5,\ 2,\ 2,\ 9,\ 5\}.

1 7, query, ans2=2ans_2 = 2, T2=2099T_2 = 2099.

1 3, query, ans3=9ans_3 = 9, T3=489076T_3 = 489076.

2 4, modification, w1..10w_{1..10} becomes {1, 6, 6, 5, 3, 5, 2, 4, 9, 5}\{1,\ 6,\ 6,\ 5,\ 3,\ 5,\ 2,\ 4,\ 9,\ 5\}.

1 3, query, ans4=10ans_4 = 10, T4=113954718T_4 = 113954718.

2 2, modification, w1..10w_{1..10} becomes {1, 6, 6, 5, 3, 5, 2, 2, 9, 5}\{1,\ 6,\ 6,\ 5,\ 3,\ 5,\ 2,\ 2,\ 9,\ 5\}.

1 9, query, ans5=2ans_5 = 2, T5=597096118T_5 = 597096118.

1 0, query, ans6=10ans_6 = 10, T6=367430437T_6 = 367430437.

1 3, query, ans7=9ans_7 = 9, T7=760521825T_7 = 760521825.

You only need to output 760521825760521825.

Sample 3:

The problem setter had enough conscience to write an explanation for this sample, but unfortunately the space is too small, so it cannot be written down.

Input Format

Output Format

Hint

Translated by ChatGPT 5