#P8573. 「DTOI-2」星之灵

「DTOI-2」星之灵

Background

Small Reminder

  • Pay attention to the letter case of CapsLock\texttt{CapsLock}.

Problem Description

Brief Statement

Repeatedly input nn strings, where:

  • When the input string is CapsLock\texttt{CapsLock}, the letter case of all subsequent strings is toggled until the next CapsLock\texttt{CapsLock} appears.
  • Given qq queries, each query asks for the xx-th string that is not CapsLock\texttt{CapsLock}.

Original Statement

The Spirit of the Stars can speak nn sentences to you, and you need to record them.

Each sentence may be a string not equal to CapsLock\texttt{CapsLock}, or it can be a command CapsLock\texttt{CapsLock}. The command controls the letter case of all letters spoken by the Spirit of the Stars. When CapsLock\texttt{CapsLock} is spoken once, all lowercase letters spoken afterwards must be changed to uppercase, and all uppercase letters must be changed to lowercase. When CapsLock\texttt{CapsLock} is spoken the second time, it returns to normal, and so on. In particular, for the CapsLock\texttt{CapsLock} command spoken by the Spirit of the Stars, you do not need to record it.

The Spirit of the Stars will keep repeating these nn sentences without changing the order, and it has qq queries. For each query, you need to tell the Spirit of the Stars what the xx-th sentence you recorded is.

Input Format

This problem uses multiple test cases.

The first line contains an integer nn.

The next line contains nn strings.

The third line contains an integer qq.

The next qq lines each contain a positive integer xx.

The meanings of n,q,xn, q, x are as described in the statement.

Output Format

Output qq lines, each containing a string, corresponding to the answer for one query.

5
CapsLock CapsLock a CapsLock B
4
1
2
3
4
a
b
A
B
7
h W CapsLock I CapsLock j CapsLock
8
7
9
13
45
20
28
50
101
I
h
H
H
j
j
W
H
10
Oh P CapsLock CapsLock CapsLock Cv Ts CapsLock XU AR 
10
84
63
414
149
25
61
50
4043
9111
47
AR
cV
AR
XU
Oh
Oh
P
XU
cV
XU

Hint

Explanation for Sample #1

The first four recorded sentences are: a,b,A,Ba, b, A, B.

Constraints

Subtask\textbf{Subtask} n,qn, q \le xx \le Special Property Score
11 1010 100100 AA 3030
22 10410^4 10510^5 /
33 10510^5 101810^{18} 4040

For all testdata, 1n,q1051 \leq n, q \leq 10^5, 1x10181 \leq x \leq 10^{18}.

Property AA: There is no CapsLock\texttt{CapsLock} among the input strings.

Data Guarantee

  • Among all sentences, there is at least one string that is not CapsLock\texttt{CapsLock}.
  • The length of every input string is at most 1010.
  • All input strings are non-empty and contain only uppercase and lowercase letters.

Translated by ChatGPT 5