AT_abc471_g.Caeser Syllables

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are KK kinds of symbols numbered 00 to K−1K-1.

Each symbol is either a vowel or not a vowel. If Vj=1V_j = 1, symbol jj is a vowel; if Vj=0V_j = 0, symbol jj is not a vowel.

Define the number of syllables of a symbol string as the number of maximal contiguous substrings of that string consisting of vowels. Formally, the number of syllables of a length-NN symbol string (a1,…,aN)(a_1, \dots, a_N) is defined as the number of pairs of integers (l,r)(l,r) satisfying 1≤l≤r≤N1 \leq l \leq r \leq N and all of the following:

  • The symbols al,…,ara_l, \dots, a_r are all vowels.
  • If l>1l > 1, symbol al−1a_{l-1} is not a vowel.
  • If r<Nr < N, symbol ar+1a_{r+1} is not a vowel.

You are given a length-NN sequence A=(A1,…,AN)A = (A_1, \dots, A_N). For each k=0,…,K−1k = 0, \dots, K-1, answer the following question:

  • Define a length-NN symbol string A′=(A1′,…,AN′)A' = (A'_1, \dots, A'_N) by Ai′:=(Ai+k) mod KA'_i := (A_i + k) \bmod K. What is the number of syllables of A′A'?

共有 KK 种符号,编号为 00 到 K−1K-1。

每种符号要么是元音,要么不是元音。若 Vj=1V_j = 1,则符号 jj 是元音;若 Vj=0V_j = 0,则符号 jj 不是元音。

定义一个符号串的音节数为该串中由元音构成的极大连续子串的个数。形式化地,长度为 NN 的符号串 (a1,…,aN)(a_1, \dots, a_N) 的音节数定义为满足 1≤l≤r≤N1 \leq l \leq r \leq N 且同时满足以下所有条件的整数对 (l,r)(l,r) 的个数:

  • 符号 al,…,ara_l, \dots, a_r 全部为元音;
  • 若 l>1l > 1,则符号 al−1a_{l-1} 不是元音;
  • 若 r<Nr < N,则符号 ar+1a_{r+1} 不是元音。

给定一个长度为 NN 的序列 A=(A1,…,AN)A = (A_1, \dots, A_N)。对每个 k=0,…,K−1k = 0, \dots, K-1,回答如下问题:

  • 定义长度为 NN 的符号串 A′=(A1′,…,AN′)A' = (A'_1, \dots, A'_N),其中 Ai′:=(Ai+k) mod KA'_i := (A_i + k) \bmod K。求 A′A' 的音节数。

输入格式

The input is given from Standard Input in the following format:

NN KK seed\mathrm{seed} MM
b1b_1 b2b_2 ⋯\cdots bMb_M
V0V_0 V1V_1 ⋯\cdots VK−1V_{K-1}

输入从标准输入中按以下格式给出:

NN KK seed\mathrm{seed} MM
b1b_1 b2b_2 ⋯\cdots bMb_M
V0V_0 V1V_1 ⋯\cdots VK−1V_{K-1}

输出格式

Output KK lines. The mm-th line (1≤m≤K1 \leq m \leq K) should contain the answer for k=m−1k = m-1.

输出 KK 行。第 mm 行(1≤m≤K1 \leq m \leq K)应包含 k=m−1k = m-1 时的答案。

输入输出样例

  • 输入#1

    4 6 12233445577788999 4
    4 2 4 1
    1 1 0 0 1 0

    输出#1

    2
    0
    1
    2
    1
    2
  • 输入#2

    15 12 998154573227378904 2
    5 6
    0 0 1 1 0 1 0 0 1 1 0 1

    输出#2

    4
    4
    3
    3
    3
    4
    4
    4
    3
    3
    3
    4
  • 输入#3

    7000000 15 409873722375451899 3
    7 0 4
    1 0 1 1 1 0 1 1 1 0 1 0 1 0 0

    输出#3

    1680078
    1681239
    1679837
    1680730
    1680470
    1679454
    1679615
    1679371
    1681263
    1679670
    1680218
    1680010
    1680211
    1680521
    1681744

说明/提示

Input Format

The input for this problem is given in a special format.

Instead of A1,…,ANA_1, \dots, A_N, the integers seed,M,b1,…,bM\mathrm{seed}, M, b_1, \dots, b_M are given from Standard Input. Restore A1,…,ANA_1, \dots, A_N using the computation represented by the following pseudocode.

Here, all variables in the pseudocode are unsigned 6464-bit integers. s⊕ts \oplus t denotes the bitwise XOR of ss and tt, s≫ts \gg t denotes ⌊s/2t⌋\lfloor s / 2^t \rfloor (the right shift operation), and s≪ts \ll t denotes s×2ts \times 2^t (the left shift operation).

state←seed\mathrm{state} \leftarrow \mathrm{seed}
for i=1,…,Ni = 1, \dots, N:
if i≤Mi \leq M:
Ai←biA_i \leftarrow b_i
else:
x←(((state≫18)⊕state)≫27) mod 232x \leftarrow \left( ((\mathrm{state} \gg 18) \oplus \mathrm{state}) \gg 27 \right) \bmod 2^{32}
r←state≫59r \leftarrow \mathrm{state} \gg 59
y←((x≫r)+(x≪(32−r))) mod 232y \leftarrow \left( (x \gg r) + (x \ll (32-r)) \right) \bmod 2^{32}
Ai←y mod KA_i \leftarrow y \bmod K
state←(state×6364136223846793005+2026081520260815) mod 264\mathrm{state} \leftarrow (\mathrm{state} \times 6364136223846793005 + 2026081520260815) \bmod 2^{64}

Sample 1 Explanation:
In this input, A=(4,2,4,1)A = (4,2,4,1).

  • For k=0k = 0, A′=(4,2,4,1)A' = (4,2,4,1), and the number of syllables is 22.
  • For k=1k = 1, A′=(5,3,5,2)A' = (5,3,5,2), and the number of syllables is 00.
  • For k=2k = 2, A′=(0,4,0,3)A' = (0,4,0,3), and the number of syllables is 11.
  • For k=3k = 3, A′=(1,5,1,4)A' = (1,5,1,4), and the number of syllables is 22.
  • For k=4k = 4, A′=(2,0,2,5)A' = (2,0,2,5), and the number of syllables is 11.
  • For k=5k = 5, A′=(3,1,3,0)A' = (3,1,3,0), and the number of syllables is 22.

Sample 2 Explanation:
In this input, A=(5,6,0,6,8,8,8,3,0,2,3,7,3,2,5)A = (5, 6, 0, 6, 8, 8, 8, 3, 0, 2, 3, 7, 3, 2, 5).

Constraints

  • 1≤N≤7×1061 \leq N \leq 7 \times 10^6
  • 1≤K≤23001 \leq K \leq 2300
  • 0≤Ai≤K−10 \leq A_i \leq K-1 (1≤i≤N1 \leq i \leq N)
  • Vj∈0,1V_j \in {0,1} (0≤j≤K−10 \leq j \leq K-1)
  • 0≤seed≤260−10 \leq \mathrm{seed} \leq 2^{60} - 1
  • 1≤M≤min⁡(N,105)1 \leq M \leq \min(N, 10^5)
  • 0≤bi≤K−10 \leq b_i \leq K-1 (1≤i≤M1 \leq i \leq M)
  • All input values are integers.

输入格式

本题的输入采用特殊格式。

不直接给出 A1,…,ANA_1, \dots, A_N,而是从标准输入中给出整数 seed,M,b1,…,bM\mathrm{seed}, M, b_1, \dots, b_M。请使用以下伪代码所表示的计算过程恢复出 A1,…,ANA_1, \dots, A_N。

其中,伪代码中所有变量均为无符号 64 位整数。s⊕ts \oplus t 表示 ss 与 tt 的按位异或(XOR),s≫ts \gg t 表示 ⌊s/2t⌋\lfloor s / 2^t \rfloor(右移操作),s≪ts \ll t 表示 s×2ts \times 2^t(左移操作)。

state←seed\mathrm{state} \leftarrow \mathrm{seed}
for i=1,…,Ni = 1, \dots, N:
if i≤Mi \leq M:
Ai←biA_i \leftarrow b_i
else:
x←(((state≫18)⊕state)≫27) mod 232x \leftarrow \left( ((\mathrm{state} \gg 18) \oplus \mathrm{state}) \gg 27 \right) \bmod 2^{32}
r←state≫59r \leftarrow \mathrm{state} \gg 59
y←((x≫r)+(x≪(32−r))) mod 232y \leftarrow \left( (x \gg r) + (x \ll (32-r)) \right) \bmod 2^{32}
Ai←y mod KA_i \leftarrow y \bmod K
state←(state×6364136223846793005+2026081520260815) mod 264\mathrm{state} \leftarrow (\mathrm{state} \times 6364136223846793005 + 2026081520260815) \bmod 2^{64}

样例 1 解释:
本输入中,A=(4,2,4,1)A = (4,2,4,1)。

  • 当 k=0k = 0 时,A′=(4,2,4,1)A' = (4,2,4,1),音节数为 22。
  • 当 k=1k = 1 时,A′=(5,3,5,2)A' = (5,3,5,2),音节数为 00。
  • 当 k=2k = 2 时,A′=(0,4,0,3)A' = (0,4,0,3),音节数为 11。
  • 当 k=3k = 3 时,A′=(1,5,1,4)A' = (1,5,1,4),音节数为 22。
  • 当 k=4k = 4 时,A′=(2,0,2,5)A' = (2,0,2,5),音节数为 11。
  • 当 k=5k = 5 时,A′=(3,1,3,0)A' = (3,1,3,0),音节数为 22。

样例 2 解释:
本输入中,A=(5,6,0,6,8,8,8,3,0,2,3,7,3,2,5)A = (5, 6, 0, 6, 8, 8, 8, 3, 0, 2, 3, 7, 3, 2, 5)。

约束条件

  • 1≤N≤7×1061 \leq N \leq 7 \times 10^6
  • 1≤K≤23001 \leq K \leq 2300
  • 0≤Ai≤K−10 \leq A_i \leq K-1(1≤i≤N1 \leq i \leq N)
  • Vj∈{0,1}V_j \in \{0,1\}(0≤j≤K−10 \leq j \leq K-1)
  • 0≤seed≤260−10 \leq \mathrm{seed} \leq 2^{60} - 1
  • 1≤M≤min⁡(N,105)1 \leq M \leq \min(N, 10^5)
  • 0≤bi≤K−10 \leq b_i \leq K-1(1≤i≤M1 \leq i \leq M)
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页