Hikawa Kyouka is participating in her clan battle, where she needs to defeat $$$m$$$ types of bosses. Each boss can appear in multiple rounds. All bosses start in round $$$1$$$ and are initially available to challenge. For a boss $$$i$$$ to become available in round $$$j$$$ ($$$j\ge 2$$$), both conditions must be met:
For example, in the picture below, because the third boss is of Round $$$60$$$, although the first boss of Round $$$61$$$ is defeated, that boss of Round $$$62$$$ won't appear.
An example of clan battle when $$$k=2$$$. The defeated label suggests that the first, fourth, and fifth bosses are unavailable. Kyouka wants to defeat $$$n$$$ bosses in order $$$a_1,a_2,\dots,a_n$$$. Can you help her determine if it is possible?
Each test contains multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1\le n\le 4\cdot10^6$$$, $$$1\le m \lt 10^6$$$, $$$1\le k\le10^9$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1\le a_i\le m$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$4\cdot10^6$$$.
If Kyouka can defeat the bosses in the order, output "YES"; otherwise, output "NO". You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
45 2 21 1 2 2 15 2 22 1 1 1 25 3 22 1 1 1 210 4 34 3 3 2 2 1 1 1 1 4
YES YES NO YES
Izumi Yuki retaliates against Kayamori Ruka's constant use of the verbal quirk teheperinko by creating a puzzle. Ruka finds herself at Nabi's ground where $$$n$$$ Nabis are arranged in a straight line. Yuki's AI assistant Ketsu reveals the challenge: assign integer values to the Nabis such that:
Help Ruka solve the puzzle!
Each test contains multiple tests. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The only line of each test case contains three integers $$$p$$$, $$$q$$$, and $$$n$$$ ($$$1\le p, q, n\le 2\cdot 10^5$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2\cdot 10^5$$$.
For each test case:
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
42 3 32 3 46 6 57 11 14
YES -2 3 -2 NO YES 1 1 1 1 1 YES 1 1 5 -13 1 1 7 1 1 3 -11 1 1 7
To help Noumi Kudryavka study math, you, as the leader of Little Busters, come up with a game on matrices. The initial matrix has $$$n$$$ rows and $$$m$$$ columns and contains $$$n\cdot m$$$ distinct integers from $$$1$$$ to $$$n\cdot m$$$.
If a row or column is dominant, Kudryavka can remove the row or column, and the remaining elements keep their order. If Kudryavka can remove the entire matrix by this operation, then you consider the matrix to be good.
You're lazy to generate such matrices, and you assign the work to others. However, you must write a checker to confirm the matrices are good.
Each test contains multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 10^6$$$, $$$1\le n\cdot m\le10^6$$$) — the number of the rows and columns in the matrix.
The $$$i$$$-th line of the next $$$n$$$ lines of each test case contains $$$m$$$ integers $$$a_{i,1},a_{i,2},\dots,a_{i,m}$$$ ($$$1\le a_{i,j}\le n\cdot m$$$). It is guaranteed that $$$a_{i,j}$$$ are pairwise distinct.
It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases doesn't exceed $$$10^6$$$.
For each test case, output "YES" if the matrix is good; otherwise, output "NO". You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
22 21 23 42 21 43 2
YES NO
Shimoe Koharu is given an array $$$a$$$ and required to find the length of its longest increasing sequence. Since Koharu doesn't know the classical problem nor the dynamic programming approach, she picks the sequence by greedy:
This algorithm is clearly wrong: for example, if $$$a=[1,4,2,3]$$$, she will get $$$[1,4]$$$ instead of the correct $$$[1,2,3]$$$. As the consultant of the Supplemental Lessons Club, you're a bit annoyed and assign her to find such sequences on all subarrays of $$$a$$$ via her approach, before she needs to sum up the length of these sequences.
However, you need to judge if her result is right. So it's now your task to calculate the sum.
Each test has multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 4\cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1\le a_i\le n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$4\cdot 10^5$$$.
For each test case, output one integer — the sum of the length of all sequences obtained by Koharu's approach on all subarrays of $$$a$$$.
31141 4 2 361 1 4 5 1 4
1 14 39
Hayama Mizuki is learning English and discovers an interesting linguistic pattern: the word "ever" appears as a suffix in "forever". Inspired by this, she creates a dynamic vocabulary system and poses a challenge to you.
Formally, she maintains a vocabulary list that undergoes the following operations:
$$$^{\text{∗}}$$$A string $$$a$$$ is a suffix of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning. For example, "ever" is a suffix of "forever", but "abc" is not a suffix of "aabbc"
The first line contains one integer $$$n$$$ ($$$1\le n\le 10^5$$$) — the number of operations that Mizuki does.
Each of the following $$$n$$$ lines contains $$$n$$$ operations. Each operation is one of the two types:
Note that a removed word can be readded into the vocabulary.
It is guaranteed that the sum of $$$|s|$$$ over all operations doesn't exceed $$$10^6$$$.
Output $$$q$$$ integers. Each integer indicates the answer after Mizuki's each operation.
10+ ever+ never+ forever+ er- never+ rever+ never+ father- er+ mother
0 1 2 5 3 6 8 9 4 4
In the game Arknights, you can cost materials to headhunt an operator, which is known as a pull. Initially, the 6-star operators' rate is $$$a\%$$$. In other words, the probability that you obtain a 6-star operator is $$$a\%$$$. If a 6-star operator does not appear after $$$c$$$ pulls, each subsequent pull will increase the 6-star operators' rate by $$$b\%$$$, up to $$$100\%$$$. For example, on the $$$(c+1)$$$-th pull, the rate increases to $$$(a+b)\%$$$, and then on the $$$(c+2)$$$-th pull, the rate increases to $$$(a+2b)\%$$$. The pull count and increased rate will be reset as soon as a 6-star operator appears on any pull.
Given $$$a$$$, $$$b$$$, and $$$c$$$, find the expected pulls between two 6-star operators. In other words, if you have just obtained a 6-star operator, find the expected pulls that you need to obtain a next 6-star operator.
Each test contains multiple tests. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^3$$$) — the number of test cases. The description of each test case follows.
The only line of each test case contains three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1\le a,b,c\le 100$$$).
For each test case, output one real number — the expected pulls between two consecutive 6-star operators.
Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.
31 1 12 2 50100 100 100
12.20996063021597 34.59455493520978 1.00000000000000
Since her creation to maintain the Tethys system, the Shorekeeper has diligently studied various algorithms under her creator's guidance. Among these, she found the Disjoint Set Union (DSU) data structure to be the most elegant. Her implementation uses the following code:
vector<int> f(n); iota(f.begin(), f.end(), 0); // initialize f[i] = i
int find(int u){ return f[u] == u ? u : f[u] = find(f[u]); } // path compression
void merge(int u, int v){ u = find(u); v = find(v); f[u] = v; }
Your task is to determine whether a given array $$$f$$$ could result from applying at most $$$n$$$ merge operations on an initially created DSU structure. The initial state uses the first code snippet above, and subsequent operations may only call the merge function.
Each test has multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 4\cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$f_0,f_1,\dots,f_{n-1}$$$ ($$$0\le f_i \lt n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$4\cdot 10^5$$$.
For each test case, if a solution exists, output as follows:
; otherwise, output $$$-1$$$ in a single line.
31021 030 1 0
0 -1 1 2 0
You're given four integers $$$l$$$, $$$r$$$, $$$y$$$, and $$$k$$$. Calculate:
$$$$$$ \sum_{x=l}^{r}\left(x\oplus y\right)^k\pmod{(10^{9}+7)} $$$$$$
where $$$\oplus$$$ denotes the bitwise XOR operation.
The only line contains four integers $$$l$$$, $$$r$$$, $$$y$$$, and $$$k$$$ ($$$1\le l\le r\le 10^9$$$, $$$1\le y\le 10^9$$$, $$$1\le k\le 10^6$$$).
Output one integer indicating the result of the formula above.
1 10 1 1
55
114 514 1919 810
353713127
Inaba Meguru, the creator of the viral Ciallo, seeks to expand her linguistic creations by combining prefixes and suffixes from two base words. Formally, she has two strings $$$s$$$ and $$$t$$$, and she will create new strings by concatenating a prefix$$$^{\text{∗}}$$$ of $$$s$$$ and a suffix$$$^{\text{†}}$$$ of $$$t$$$. She wants to know how many different non-empty strings she can obtain in this way.
$$$^{\text{∗}}$$$A string $$$a$$$ is a prefix of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the end. For example, "for" is a prefix of "forever", but "abc" is not a prefix of "aabbc"
$$$^{\text{†}}$$$A string $$$a$$$ is a suffix of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning. For example, "ever" is a suffix of "forever", but "abc" is not a suffix of "aabbc"
Each test contains multiple tests. The first line contains one integer $$$T$$$ ($$$1\le T\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test contains a string $$$s$$$ $$$(1\le |s|\le 10^6)$$$.
The second line of each test contains a string $$$t$$$ $$$(1\le |t|\le 10^6)$$$.
It is guaranteed that both $$$s$$$ and $$$t$$$ contain only lower case Latin characters.
It is guaranteed that neither the sum of $$$|s|$$$ nor the sum of $$$|t|$$$ over all test cases exceeds $$$10^6$$$.
For each test case, output an integer indicating the number of different strings Meguru can obtain.
4aaabciaohelloinabameguruayachinene
2 3 28 122
Bidding is the first phase of a bridge game where players communicate their hand strength and distribution to determine the contract (the final goal for the round). The rules of bidding are listed as follows.
You're given a bidding sequence. Determine if it is both valid (follows all rules) and complete (meets an ending condition).
Each test contains multiple tests. The first line contains one integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains one integer $$$n$$$ ($$$1\le n\le 320$$$) — the length of the bidding sequence.
The second line contains $$$n$$$ strings which indicate each player's bids. It is guaranteed that the bids are valid.
For each test case, if the bidding sequence is valid, output "YES"; otherwise, output "NO". You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
64P P P P5P P P P X5P 1C P P P6P P 1C 1D P P8P 1H X XX X P P P121S P 2C P 2D P 4S X XX P P P
YES NO YES NO NO YES
Although Ororon is from the Master of the Night Wind, his weaving skills leave much to be desired. His creations resemble patterned towels more than proper woven scrolls. When the tribe's master artisans abandon hope of improving his craftsmanship, Ororon turns to sketching designs with pen and paper.
His grandmother Citlali, the renowned Granny Itztli, devises a challenge. She provides a tree with $$$n$$$ vertices and $$$m$$$ colored path operations. The operations are divided into two types:
For the operation of the first type, Ororon is given a vertex pair $$$(u,v)$$$ and a color $$$c$$$. He must paint all vertices along the unique simple path between $$$u$$$ and $$$v$$$ with color $$$c$$$. Each painting operation completely overwrites previous colors on those vertices.
For the operation of the second type, Ororon is also given a vertex pair $$$(u,v)$$$ and a color $$$c$$$. He must paint all vertices of the subtree$$$^{\text{∗}}$$$ of $$$u$$$ with $$$c$$$, assuming $$$v$$$ is the root of the tree. Note that $$$v$$$ is assumed as the root only in the current operation.
Being an expert shaman, Citlali already knows all final colors — her goal is to verify Ororon's work. Of course, Ororon also hates tedious painting, so help him determine the final color of every vertex after processing all $$$m$$$ operations in order.
$$$^{\text{∗}}$$$The subtree of a vertex $$$u$$$ is the set of all vertices that pass through $$$u$$$ on a simple path to the root.
Each test has multiple test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of each test case follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n\le 4\cdot 10^5$$$, $$$1\le m\le 2\cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1\le a_i\le 10^6$$$) — the initial color of each vertex.
The $$$i$$$-th line of the following $$$n-1$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1\le x_i, y_i\le n$$$), describing an edge between vertex $$$x_i$$$ and $$$y_i$$$. It is guaranteed that these edges form a tree.
The $$$i$$$-th line of the following $$$m$$$ lines contains four integers $$$op_i$$$, $$$u_i$$$, $$$v_i$$$ and $$$c_i$$$ ($$$1\le op_i\le 2$$$, $$$1\le u_i,v_i \le n$$$, $$$1\le c_i\le 10^6$$$) — the type of the $$$i$$$-th operation and its parameters.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$4\cdot 10^5$$$, and the sum of $$$m$$$ over all test cases doesn't exceed $$$2\cdot10^5$$$.
For each test case, output $$$n$$$ integers — the final color of each vertex.
21 211 1 1 42 1 1 58 41 2 3 4 5 6 7 88 16 74 67 53 25 25 12 4 4 51 3 4 61 1 7 22 5 6 1
5 1 1 1 6 1 6 2 1
This is an interactive problem.
You're invited by Firefly to a garden, where $$$10^5$$$ trees are lined up. The trees are numbered from $$$1$$$ to $$$10^5$$$ from left to right. She tells you she has put $$$n$$$ groups of fyreflies, each group located at a distinct secret tree $$$x_i$$$, and she would like to play a game with you. You can query a coordinate $$$x$$$, and Firefly will tell you the sum of the Manhattan distance$$$^{\text{∗}}$$$ between your guess and each group's coordinates.
However, there is little time for Firefly to spend with you, and you have to come up with one of the groups' coordinates within $$$40$$$ queries. If you manage to do so, she can take you to the coordinate and enjoy the fyreflies with you. If you fail, she will have to say farewell and carry out her mission.
$$$^{\text{∗}}$$$The Manhattan distance between two coordinates $$$x_1$$$ and $$$x_2$$$ is given by $$$|x_1-x_2|.$$$
Each test contains multiple tests. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^3$$$) — the number of test cases. The description of each test case follows.
The first line contains one integer $$$n$$$ ($$$1\le n\le10^4$$$) — the number of fyrefly groups.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^4$$$.
To make a query, output a line in the following format (do not include quotes):
"$$$\mathtt{?}$$$ $$$x$$$" ($$$1\le x\le 10^5$$$)
Here, $$$x$$$ represents your query coordinate.
After each query, you should read a line containing one integer, indicating the sum of the Manhattan distance between your guess and each group's coordinates. In other words, the integer is $$$\displaystyle{\sum_{i=1}^{n}|x_i-x|}$$$.
When you are ready to print the answer, output a single line in the following format:
"$$$\mathtt{!}$$$ $$$x$$$" ($$$1\le x\le 10^5$$$)
Here, $$$x$$$ represents your answer coordinate.
You can make at most $$$40$$$ queries in each test case.
The interactor is NOT adaptive, meaning that the answer is known before the participant asks the queries and doesn't depend on the queries asked by the participant.
If your program makes more than $$$40$$$ queries for one test case, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output the end of line and flush the output. Otherwise, you may get Idleness limit exceeded verdict. To do this, use:
2 7 34 25 4
? 12 ? 5 ! 1 ! 42657
In the first sample case, $$$x=[13,5,10,8,9,6,1]$$$.
In the second sample case, $$$x=[85688,42657,37978,85893]$$$.
As the manager of the magical library of the Yuugyuuji's, Chrysoberyl can extract any contiguous subsequence from an existing magical book to create a new tome. The magical books are composed solely of parentheses "(" and ")". A book is considered beautiful if its content strictly adheres to the following formal grammar:
Chrysoberyl possesses $$$q$$$ identical old magical books. Due to the ancient nature of these books, their opening and closing sections have become unusable. Specifically, for the $$$i$$$-th book, she must select a substring between positions $$$l_i$$$ and $$$r_i$$$ (inclusive). Two selection methods are considered different if and only if they have distinct starting positions or distinct ending positions, even if their content is identical.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1\le n$$$, $$$q\le 2\cdot10^5$$$) — the length of each magical book's content and the number of the magical books.
The second line contains $$$n$$$ characters $$$s_1,s_2,\dots,s_n$$$ ($$$s_i=\mathtt{'('}$$$ or $$$\mathtt{')'}$$$) — each magical book's content.
Each of the following $$$q$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1\le l_i\le r_i\le n$$$).
Output $$$q$$$ integers. The $$$i$$$-th integer represents the number of different ways that Chrysoberyl can create a beautiful book from the $$$i$$$-th book.
12 7())(())(())(1 12 31 21 128 125 112 10
0 0 1 6 2 3 3