Given a set of $$$n$$$ binary strings, each containing only the digits $$$\texttt{0}$$$ and $$$\texttt{1}$$$, you need to find an arrangement of these strings that minimizes the total number of inverse pairs in the final concatenated string. You may rearrange the strings in any order to achieve the minimum number of inverse pairs in the concatenated string.
Let's denote the $$$i$$$-th digit of the final concatenated string as $$$s_i$$$. An inverse pair is defined as a pair of indices $$$(i,j)$$$ such that $$$i \lt j$$$ and $$$s_i \gt s_j$$$.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^6$$$), indicating the number of binary strings.
Each of the next $$$n$$$ lines contains a binary string. The sum of the lengths of all binary strings does not exceed $$$10^6$$$.
Output a single integer representing the minimum number of inverse pairs.
3 1 11 101
1
For the sample, the final concatenated string with the minimum number of inverse pairs is $$$\texttt{101111}$$$.
The sum of the points of the remaining cards in a deck of playing cards after removing the jokers can be easily calculated as follows: $$$\dfrac{4 \times 13 \times (13+ 1)}{2} = 364$$$. We define numbers like $$$364$$$ as Poker Numbers, as they can be written as $$$K \cdot \dfrac{X(X+1)}{2}$$$ for some $$$K\ge 1, X \ge 2$$$.
Your task is to solve the following problem. Given $$$n, c, p$$$, compute:
$$$$$$ \left( \sum\limits_{u \in S_n}c^{u} \right) \bmod p $$$$$$
where $$$S_n$$$ denotes the set of Poker Numbers between $$$1$$$ and $$$n$$$.
The first line contains an integer $$$T$$$ ($$$1\le T \le 20$$$), representing the number of test cases.
Each test case consists of a single line containing three integers $$$n,c,p$$$ ($$$1\le n \le 10^{10}$$$, $$$1 \le c \lt p \le 10^{9} + 7$$$). It is guaranteed that $$$p$$$ is a prime.
For each test case, output the answer in a single line.
210 2 100000000720 2 1000000007
1608 1349192
For $$$n=10$$$, $$$S_{10}=\{3,6,9,10\}$$$, so for the first example, the answer is $$$2^3+2^6+2^9+2^{10}=1608$$$.
A delivery robot is an autonomous machine designed to provide delivery services. On many campuses, such as UESTC, these robots can offer significant convenience to students.
A delivery robot typically integrates various assistance systems, such as collision avoidance systems. These systems should enable the robot to automatically avoid both static obstacles and other robots. Due to the non-immediate nature of velocity control, collision avoidance systems typically allocate a time interval $$$\Delta t$$$. If a collision is predicted to occur within $$$\Delta t$$$ at the current velocity, the system adjusts the robot's velocity accordingly, including its speed and direction.
In this problem, we simplify the collision detection model by considering the motion of two circles $$$A,B$$$ on a plane, with $$$\Delta t=1$$$. The circles' radii $$$r_A,r_B$$$, their center positions $$$P_A,P_B$$$, and their current velocities $$${\bf{v}}_A,{\bf{v}}_B$$$ are given. It is guaranteed that the circles are strictly disjoint at the start, and we assume a collision occurs when the circles intersect. With circle $$$B$$$'s velocity remaining constant, the velocity of circle $$$A$$$ may need to be adjusted to prevent a collision within $$$\Delta t=1$$$, i.e. to change $$${\bf{v}}_A$$$ into $$${\bf{v}}'_A$$$. We assume that the velocity can change instantly at the beginning of $$$\Delta t$$$ but remains constant throughout $$$\Delta t$$$. In this problem, you only need to consider the first $$$\Delta t=1$$$ from the current starting point, without considering the subsequent process.
Without an upper limit on speed, it is evident that a suitable $$${\bf{v}}'_A$$$ must exist to prevent a collision within $$$\Delta t=1$$$. Depending on the situation, different strategies can be used to select $$${\bf{v}}'_A$$$. The objective of this problem is to choose a $$${\bf{v}}'_A$$$ that minimizes the magnitude of the difference between $$${\bf{v}}_A$$$ and $$${\bf{v}}'_A$$$, i.e. $$${\bf{v}}'_A=\arg\min_{\bf{v}}\Vert {\bf{v}}_A-{\bf{v}}\Vert$$$. The magnitude of a vector $$${\bf{u}}=(x,y)$$$ is defined as $$$\Vert{\bf{u}}\Vert=\sqrt{x^2+y^2}$$$.
The first line contains an integer $$$T$$$ ($$$1\le T \le 10^5$$$), indicating the number of test cases.
The first line of each test case contains five integers $$$r_A,x_{P_A},y_{P_A},x_{{\bf{v}}_A},y_{{\bf{v}}_A}$$$ ($$$0 \lt r_A\le 10^9$$$, $$$-10^9 \le x_{P_A},y_{P_A},x_{{\bf{v}}_A},y_{{\bf{v}}_A} \le 10^9$$$), where $$$P_A=(x_{P_A},y_{P_A})$$$, $$${\bf{v}}_A=(x_{{\bf{v}}_A},y_{{\bf{v}}_A})$$$.
The second line of each test case contains five integers $$$r_B,x_{P_B},y_{P_B},x_{{\bf{v}}_B},y_{{\bf{v}}_B}$$$ ($$$0 \lt r_B\le 10^9$$$, $$$-10^9 \le x_{P_B},y_{P_B},x_{{\bf{v}}_B},y_{{\bf{v}}_B} \le 10^9$$$), where $$$P_B=(x_{P_B},y_{P_B})$$$, $$${\bf{v}}_B=(x_{{\bf{v}}_B},y_{{\bf{v}}_B})$$$.
It is guaranteed that the two circles are strictly disjoint.
For each test case, output the minimum magnitude of $$${\bf{v}}_A-{\bf{v}}'_A$$$, i.e.$$$\min\Vert{\bf{v}}_A-{\bf{v}}'_A\Vert$$$, in a single line. Your answer will be considered correct if its relative or absolute error does not exceed $$$10^{-6}$$$, i.e. $$$\frac{|a-b|}{\max(1,b)}\le 10^{-6}$$$ if your answer is $$$a$$$ and the correct answer is $$$b$$$.
31 1 1 3 33 5 5 -3 -31 1 1 1 13 5 5 0 -11 1 1 -1 -13 5 5 1 1
6.0000000000 0.3944487245 0.0000000000
Given an integer $$$n$$$, your task is to find the expectation of the length of the longest non-decreasing subsequence in a binary string, i.e. a sequence consisting of either $$$\texttt{0}$$$ or $$$\texttt{1}$$$, of length $$$n$$$.
A subsequence is a sequence that can be derived from another sequence by deleting zero or more elements without changing the order of the remaining elements. For example, $$$[1,2,3]$$$ is a subsequence of $$$[1,4,2,5,3]$$$, while $$$[1,3,2]$$$ is not. In the context of a binary string, a non-decreasing subsequence will consist of a series (possibly zero) of $$$\texttt{0}$$$s followed by a series (possibly zero) of $$$\texttt{1}$$$s.
You should output the answer modulo $$$M$$$. That is, representing the answer as a rational fraction $$$\frac{a}{b}$$$, your output should be the smallest non-negative integer $$$x$$$ that satisfies $$$a \equiv bx \pmod{M}$$$, where $$$M$$$ is a given prime number.
The first line contains an integer $$$T$$$ ($$$1\le T \le 1000$$$), denoting the number of test cases.
Each test case contains two integers $$$n, M$$$ ($$$1\le n \le 5000$$$, $$$10^8\le M \le 10^9$$$). $$$M$$$ is prime.
It is guaranteed that $$$\sum n \le 5000$$$ over all test cases.
For each test case, output the answer modulo $$$M$$$ in a single line.
22 9982443533 998244853
249561090 499122429
For $$$n = 2$$$, we have four sequences: $$$\texttt{00},\texttt{01},\texttt{10},\texttt{11}$$$, each with a probability of $$$\frac{1}{4}$$$. The lengths of their longest non-decreasing subsequences are $$$2, 2, 1, 2$$$, respectively. Therefore, the answer is $$$\frac{1}{4} \times (2 + 2 + 1 + 2) = \frac{7}{4}$$$.
The cultivation of UESTC master's students adopts a combination of coursework and thesis research. Through coursework and thesis research, students systematically master the theoretical knowledge in their discipline and develop problem-solving abilities.
The total credits for a master's degree are divided into two parts: course credits and compulsory sessions. Courses in course credits are divided into two categories: degree courses and non-degree courses. Degree courses include public foundational courses and professional foundational courses. Non-degree courses include professional elective courses, interdisciplinary elective courses, and other elective courses.
To complete the program, students must meet the following credit requirements:
Now, given a course selection plan, including the course names, course types, and credits for each course, please determine if the plan meets the credit requirements.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 100$$$), indicating the number of test cases.
The first line of each test case contains seven integers $$$a,b,c,d,e,f,g$$$ ($$$1 \leq a,b,c,d,e,f,g \leq 100$$$, $$$a \geq b+c$$$, $$$b \geq d \gt f$$$, $$$b \geq e \geq f+g$$$), the meanings of which are described above.
The second line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$), indicating the number of selected courses.
The following $$$3n$$$ lines describe the $$$n$$$ courses, with each course occupying three lines. The first line contains the course name with a maximum length of $$$50$$$, consisting of only English letters and spaces. All the course names are different from others, and spaces will not appear at the beginning and the end of the names. The second line contains the course type, which is one of public foundational courses, professional foundational courses, professional elective courses, interdisciplinary elective courses, other elective courses, and compulsory sessions. The third line contains an integer representing the course credit, ranging within $$$[1,10]$$$.
For each test case, output $$$\texttt{YES}$$$ in a single line if the plan meets the credit requirements, otherwise output $$$\texttt{NO}$$$ in a single line.
1 28 24 4 15 15 6 7 15 Socialism with Chinese Characteristics public foundational courses 2 Matrix Theory professional foundational courses 3 Optimization Theory professional foundational courses 3 Communication Network Theory professional elective courses 2 Bayesian Learning and Random Matrix professional elective courses 2 Image and Video Processing professional foundational courses 2 Graph Theory professional foundational courses 3 Machine Learning professional elective courses 2 Visual Data Analysis professional elective courses 2 Guidance on Writing Graduate Thesis other elective courses 1 Graduate English public foundational courses 3 Teaching Practice compulsory sessions 1 Academic Activities compulsory sessions 1 General Education Elective Courses compulsory sessions 1 Academic Exchange compulsory sessions 1
YES
As we all know, the mode of a multiset refers to the number that appears most frequently in the multiset. One day, Poro is curious about calculating the number of occurrences of the mode in a given multiset. As Dango happens to pass by, the problem is quickly resolved.
However, Poro then scatters numerous cookies of various sizes and wants to determine the maximum number of cookies that satisfy the following condition:
Dango is initially perplexed, but upon examining the cookies twice, she realizes that the maximum size of the chosen subset must be greater than half of the total number of cookies. Now, Dango knows how to compute the answer to this question. As she spots you passing by, she decides to test whether you can solve this problem as well.
Please note that the memory limit for this problem is 1 megabyte.
The first line contains two integers $$$n,k$$$ ($$$1\le n \le 10^6$$$, $$$0\le k \le 9$$$), indicating the size of the multiset and the limit $$$k$$$.
The second line gives the size of cookies $$$a_i$$$ ($$$1\le i\le n$$$, $$$0\le a_i\le 10^9$$$)
The third line gives the size of cookies $$$a_i$$$ again.
Output one integer indicating the answer.
6 3 1 1 4 5 1 4 1 1 4 5 1 4
5
Are you familiar with the Josephus problem? To put it simply, imagine $$$n$$$ people standing in a circle, numbered from $$$1$$$ to $$$n$$$ in a clockwise order. A counting process begins with person $$$1$$$, and every $$$k$$$-th person in the clockwise direction is eliminated from the circle. After a person is eliminated, the counting resumes from the next person still in the circle. This process continues until only one person remains. The primary question is: who will be the last person remaining?
Mathematician Little J has already solved this problem, but he's now interested in a variation. He wants to determine the order in which individuals are eliminated if each person has a specific number of lives, denoted by $$$a_i$$$. In this scenario, the $$$k$$$-th person in the clockwise direction loses one life each time they are selected, and they are removed from the circle only when their life count reaches zero.
The first line contains two positive integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 5 \times 10^4$$$, $$$1 \le k \le 100$$$).
The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$), representing the number of lives each person has.
Output a permutation of the integers from $$$1$$$ to $$$n$$$ in $$$n$$$ lines, representing the order in which people are removed.
5 2 5 5 5 7 6
2 1 3 5 4
Xiaomei is watching a video about the popular song rankings from recent years. When she sees various comments on the screen like "too high", "too low", and "reasonable", her train of thought is disrupted. However, she also believes that the current ranking list is not very reasonable. Therefore, she wants to create a new list based on these comments.
Since there are too many comments, Xiaomei will collect and consolidate a more unified opinion for each song. There are three types of opinions:
Each song has exactly one consolidated opinion. Xiaomei wants to know if it is possible to create a new list that satisfies all the opinions.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 300$$$), representing the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), representing the number of songs on the list.
Each of the next $$$n$$$ lines contains two integers $$$p$$$ and $$$x$$$ ($$$-1 \le p \le 1$$$, $$$1 \le x \le n$$$), representing an opinion for the song ranked $$$x$$$. It is guaranteed that each song has exactly one opinion.
It is guaranteed that $$$\sum n \le 2 \times 10^5$$$ over all test cases.
For each test case, output $$$n$$$ integers in a single line representing the new list of the song board if a satisfactory list can be created, where the $$$i$$$-th integer $$$a_i$$$ indicates that the new rank of the song originally ranked $$$a_i$$$ is $$$i$$$. If there are multiple solutions, output any. If there is no solution, output $$$\texttt{-1}$$$ in a single line.
221 1-1 250 2-1 3-1 40 1-1 5
2 1 -1
Before Kiana travels to the moon, she must take a subway to bid farewell to her friends. However, an unexpected challenge arises: she must construct the subway herself.
Kiana's task is to build a cuboid subway with dimensions $$$w \times h \times l$$$. Prior to building the subway, she must create a time-stasis field of the same size. In her form as the Herrscher of Finality, Kiana can generate non-intersecting cuboid spaces, which can then be assembled to create the required field.
However, there are constraints on the small spaces: each cuboid space must have at least one face that is a square. In other words, if the dimensions of the cuboid space are $$$a \times b \times c$$$, then at least one of the following conditions must hold: $$$a=b, b=c$$$, or $$$a=c$$$.
Since Kiana's power is limited, she seeks your assistance as captain to develop a plan to accomplish the task.
A single line containing three integers $$$w, h, l$$$ ($$$1\le w,h,l \le 10^9$$$), representing the dimensions of the required field. You can envision this field as a cuboid with the lower left corner at $$$(0,0,0)$$$ and the upper right corner at $$$(w,h,l)$$$.
The first line contains an integer $$$n$$$ ($$$1\le n \le 10^5$$$), representing the number of spaces generated.
Each of the next $$$n$$$ lines contains $$$6$$$ integers $$$x_l, y_l, z_l, x_r, y_r, z_r$$$ ($$$0 \leq x_l \lt x_r \leq w$$$, $$$0 \leq y_l \lt y_r \leq h$$$, $$$0 \leq z_l \lt z_r \leq l$$$), representing a cuboid space with its lower left corner at $$$(x_l,y_l,z_l)$$$ and upper right corner at $$$(x_r,y_r,z_r)$$$.
Your solution must ensure that no two spaces intersect and that all spaces fit together to form the required field precisely.
3 5 7
4 0 0 0 3 3 7 0 3 0 2 5 7 2 3 0 3 4 7 2 4 0 3 5 7