#P8992. [北大集训 2021] 扑克比大小
[北大集训 2021] 扑克比大小
Background
CTT2021 D3T3
Problem Description
Little and Little are playing a poker card comparison game.
The rules of their game are as follows:
-
Before the game starts, the system deals a pile of hand cards to Little and a pile of hand cards to Little (the numbers of cards in the two piles may be different). Each card has a lowercase letter written on it.
-
In each round of the game, Little and Little simultaneously flip the first card on the top of their piles. If the two flipped cards are different, then the player whose card corresponds to the smaller lowercase letter wins. If the two flipped cards are the same, they put the flipped cards into the bottom of their piles and continue the game until one side wins.
In fact, the system deals cards from a huge deck. Specifically, suppose the deck has cards, which are . Then the system randomly selects cards from the -th card to the -th card to deal to a player. In other words, from the top of the pile to the bottom of the pile, the cards are .
Now Little and Little will play a total of games. Little learns in some way that, in the -th game, the cards dealt to Little are . Little wants to know how many possible hand card piles he could have that would allow him to beat Little . Two hand card piles are considered different if and only if the numbers of cards in the two piles are different, or there exists a position such that the cards at distance from the top of the piles are different.
Input Format
The first line contains a string consisting only of lowercase letters.
The second line contains a positive integer and an integer , where indicates the data type.
The next lines each contain two integers and on line .
Output Format
Output lines. Each line contains an integer indicating how many possible hand card piles Little could have that would allow him to beat Little .
abbab
5 0
1 3
2 4
3 5
1 4
2 5
4
7
6
2
8
Hint
For all testdata, it holds that , .
| Subtask | Score | |||
|---|---|---|---|---|
The meaning of data type is as follows:
-
: The data has no special restrictions.
-
: It is guaranteed that , .
-
: It is guaranteed that , if , then it must hold that .
-
: It is guaranteed that .
Here denotes the string . The result of concatenating two strings is the string obtained by appending after in order.
Translated by ChatGPT 5