text
stringlengths 0
801
|
---|
The first line contains an integer $n$ ($1\le n\le 700$). |
The second line contains $n$ integers $a_1,\ldots,a_n$ ($0\le a_i<998\,244\,353$). |
The third line contains $n$ integers $b_1,\ldots,b_n$ ($0\le b_i<998\,244\,353$). |
The fourth line contains $n$ integers $c_0,\ldots,c_{n-1}$ ($0\le c_i<998\,244\,353$). |
Print $n$ integers: the $i$-th one is $f(i)$ modulo $998\,244\,353$. |
In the second example: |
* Consider permutation $[1,2,3]$. Indices $1,2,3$ are prefix maximums. Index $3$ is the only suffix maximum. Indices $2,3$ are ascents. In conclusion, it has $3$ prefix maximums, $1$ suffix maximums, and $2$ ascents. Therefore, its cost is $a_3b_1c_2=12$. * Permutation $[1,3,2]$ has $2$ prefix maximums, $2$ suffix maximums, and $1$ ascent. Its cost is $6$. * Permutation $[2,1,3]$ has $2$ prefix maximums, $1$ suffix maximum, and $1$ ascent. Its cost is $4$. * Permutation $[2,3,1]$ has $2$ prefix maximums, $2$ suffix maximums, and $1$ ascent. Its cost is $6$. * Permutation $[3,1,2]$ has $1$ prefix maximum, $2$ suffix maximums, and $1$ ascent. Its cost is $3$. * Permutation $[3,2,1]$ has $1$ prefix maximum, $3$ suffix maximums, and $0$ ascents. Its cost is $3$. |
The sum of all permutations' costs is $34$, so $f(3)=34$. |
The two versions are different problems. You may want to read both versions. You can make hacks only if both versions are solved. |
You are given two positive integers $n$, $m$. |
Calculate the number of ordered pairs $(a, b)$ satisfying the following conditions: |
* $1\le a\le n$, $1\le b\le m$; * $b \cdot \gcd(a,b)$ is a multiple of $a+b$. |
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le 10^4$). The description of the test cases follows. |
The first line of each test case contains two integers $n$, $m$ ($1\le n,m\le 2 \cdot 10^6$). |
It is guaranteed that neither the sum of $n$ nor the sum of $m$ over all test cases exceeds $2 \cdot 10^6$. |
For each test case, print a single integer: the number of valid pairs. |
In the first test case, no pair satisfies the conditions. |
In the fourth test case, $(2,2),(3,6),(4,4),(6,3),(6,6),(8,8)$ satisfy the conditions. |
A movie company has released $2$ movies. These $2$ movies were watched by $n$ people. For each person, we know their attitude towards the first movie (liked it, neutral, or disliked it) and towards the second movie. |
If a person is asked to leave a review for the movie, then: |
* if that person liked the movie, they will leave a positive review, and the movie's rating will increase by $1$; * if that person disliked the movie, they will leave a negative review, and the movie's rating will decrease by $1$; * otherwise, they will leave a neutral review, and the movie's rating will not change. |
Every person will review exactly one movie — and for every person, you can choose which movie they will review. |
The company's rating is the minimum of the ratings of the two movies. Your task is to calculate the maximum possible rating of the company. |
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. |
The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$). |
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-1 \le a_i \le 1$), where $a_i$ is equal to $-1$ if the first movie was disliked by the $i$-th viewer; equal to $1$ if the first movie was liked; and $0$ if the attitude is neutral. |
The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ($-1 \le b_i \le 1$), where $b_i$ is equal to $-1$ if the second movie was disliked by the $i$-th viewer; equal to $1$ if the second movie was liked; and $0$ if the attitude is neutral. |
Additional constraint on the input: the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. |
For each test case, print a single integer — the maximum possible rating of the company, if for each person, choose which movie to leave a review on. |
You are given a matrix, consisting of $n$ rows and $m$ columns. |
You can perform two types of actions on it: |
* paint the entire column in blue; * paint the entire row in red. |
Note that you cannot choose which color to paint the row or column. |
In one second, you can perform either one action or multiple actions at the same time. If you perform one action, it will be free. If you perform $k > 1$ actions at the same time, it will cost $k^2$ coins. When multiple actions are performed at the same time, for each cell affected by actions of both types, the color can be chosen independently. |
You are asked to process $q$ queries. Before each query, all cells become colorless. Initially, there are no restrictions on the color of any cells. In the $i$-th query, a restriction of the following form is added: |
* $x_i~y_i~c_i$ — the cell in row $x_i$ in column $y_i$ should be painted in color $c_i$. |
Thus, after $i$ queries, there are $i$ restrictions on the required colors of the matrix cells. After each query, output the minimum cost of painting the matrix according to the restrictions. |
The first line contains three integers $n, m$ and $q$ ($1 \le n, m, q \le 2 \cdot 10^5$) — the size of the matrix and the number of queries. |
In the $i$-th of the next $q$ lines, two integers $x_i, y_i$ and a character $c_i$ ($1 \le x_i \le n$; $1 \le y_i \le m$; $c_i \in$ {'R', 'B'}, where 'R' means red, and 'B' means blue) — description of the $i$-th restriction. The cells in all queries are pairwise distinct. |
Print $q$ integers — after each query, output the minimum cost of painting the matrix according to the restrictions. |
We define the $\operatorname{MAD}$ (Maximum Appearing Duplicate) in an array as the largest number that appears at least twice in the array. Specifically, if there is no number that appears at least twice, the $\operatorname{MAD}$ value is $0$. |
For example, $\operatorname{MAD}([1, 2, 1]) = 1$, $\operatorname{MAD}([2, 2, 3, 3]) = 3$, $\operatorname{MAD}([1, 2, 3, 4]) = 0$. |
You are given an array $a$ of size $n$. Initially, a variable $sum$ is set to $0$. |
The following process will be executed in a sequential loop until all numbers in $a$ become $0$: |
1. Set $sum := sum + \sum_{i=1}^{n} a_i$; 2. Let $b$ be an array of size $n$. Set $b_i :=\ \operatorname{MAD}([a_1, a_2, \ldots, a_i])$ for all $1 \le i \le n$, and then set $a_i := b_i$ for all $1 \le i \le n$. |
Find the value of $sum$ after the process. |
The first line contains an integer $t$ ($1 \leq t \leq 2 \cdot 10^4$) — the number of test cases. |
For each test case: |
* The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the size of the array $a$; * The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of the array. |
It is guaranteed that the sum of $n$ over all test cases will not exceed $2 \cdot 10^5$. |
For each test case, output the value of $sum$ in a new line. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.