#P17287. [Algo Beat Contest 013 & MSOI R2] 付之一笑

[Algo Beat Contest 013 & MSOI R2] 付之一笑

Background

"Whether you gain or lose, just laugh it off."

Problem Description

You are given qq ciphertexts. Each ciphertext consists of lowercase letters and “garbled codes”. There are 2626 kinds of “garbled codes”, which are the 2626 Arabic numerals from 11 to 2626. The letter corresponding to 11 is aa, 22 corresponds to bb, and so on.

Now you are given an operation value pp:

  • When pp equals 11, you need to convert all “garbled codes” in the ciphertext into lowercase letters. Specifically, you should treat each maximal consecutive digit segment as one “garbled code” and translate it into a single letter.
  • When pp equals 22, you need to convert all lowercase letters in the ciphertext into “garbled codes”.

Input Format

The first line contains an integer qq, meaning there are qq ciphertexts.

In the next qq lines, each line contains an integer pp and a string sis_i, representing the operation value and the ciphertext, respectively.

Output Format

Output qq lines. Each line contains the ciphertext after performing the required operation.

3
1 a9y3tf2p25p
2 jzc8ph4ph4ph
2 ph12pjzc21noi20ag26
aiyctfbpyp
10263816841684168
1681216102632114159201726

Hint

Constraints

This problem uses bundled testdata.

::cute-table{tuack}

Subtask ID qq \le si\lvert s_i \rvert \le Special Property Score
11 2×1052\times 10^5 10310^3 p=1p=1, and the garbled codes only include 11 to 99 2020
22 ^ p=2p=2, and the ciphertext only includes lowercase letters
33 2×1052\times 10^5 The garbled codes only include 11 to 99
44 None 4040

For all data, it holds that:

  • 1q2×1051 \le q \le 2 \times 10^5
  • 1si2×1051 \le \lvert s_i \rvert \le 2 \times 10^5
  • si2×105\sum \lvert s_i \rvert \le 2 \times 10^5
  • p{1,2}p \in \{1,2\}
  • It is guaranteed that the ciphertext contains only lowercase letters and digit characters.
  • When p=1p=1, the number represented by every maximal consecutive digit segment in the ciphertext is within [1,26][1,26].

Translated by ChatGPT 5