Print the number, modulo $$$998244353$$$, of integer sequences $$$A = (A_1, A_2, \dots, A_N)$$$ with length $$$N$$$ that satisfy both of the following conditions.
The problem is too easy, so output the answer for each $$$N = 1, 2, \dots, NMAX$$$.
In the first line, $$$NMAX, M, X$$$ ($$$1\leq NMAX \leq 10^5, 0\leq M, X \lt 2^{60}$$$).
$$$NMAX$$$ lines — the answers for $$$N = 1, 2, \dots, NMAX$$$.
5 6 7
0 3 7 25 49
10 100 0
1 101 1418 38280 756912 13403840 203823022 755806367 368916768 79402702
You are given a binary string $$$S$$$. You can perform the following operation any number of times:
A binary string $$$S$$$ ($$$1\leq |S| \leq 5\times 10^6$$$).
One integer — the answer.
10100010011001011111
5
0000010101100110101101010110000110100\ 1110000100101111111001011011101010001\ 11101111010101010010101010 (There won’t be extra line breakers \ in the actual test cases.)
58
You are given $$$m$$$ equations of the form $$$$$$a_i \cdot x + err_i \equiv c_i \pmod p.$$$$$$ Here, $$$err_i$$$ is an unknown random error term, chosen uniformly at random from $$$-\lfloor \frac{p}{200} \rfloor, \ldots, \lfloor \frac{p}{200} \rfloor$$$, while $$$a_i, c_i$$$ and $$$p$$$ are known to you.
You know that these equations hold for some unknown integer $$$x$$$. Find one such $$$x$$$.
In the first line, $$$T$$$ ($$$1\leq T\leq 500$$$) — the number of test cases. For each test case:
For each test case, one integer — the answer. If there are multiple solutions, you may output any.
1 50 922033901407246477 492300877907148697 8585039545574817 36478175140515505 237143454432095134 537753813197233578 694568987600933631 ... (truncated)
578607642570710976
The full sample test case is available in the contest system.
For a nonnegative integer $$$x$$$, let $$$f(x)$$$ and $$$g(x)$$$ denote the digit sum of $$$x$$$ in binary and ternary, respectively.
Given $$$n, a, b, c$$$, compute $$$$$$\left(\sum_{i=1}^n a^i b^{f(i)} c^{g(i)} \right) \bmod 998244353.$$$$$$
In the first line, $$$n, a, b, c$$$ ($$$1\leq n\leq 10^{13}, 1\leq a, b, c \lt 998244353$$$).
One integer — the answer.
123456 12345 234567 3456789
664963464
9876543210987 12816 837595 128478
7972694
This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them?
Let $$$p$$$ be an odd prime. Compute the number of quadratic residues in $$$[l, r]$$$.
$$$x$$$ is a quadratic residue of $$$p$$$ iff $$$x^{(p-1)/2} \equiv 1 \pmod p$$$.
In the first line, $$$p, l, r$$$ ($$$3\leq p \leq 10^{11}, 1\leq l\leq r \lt p$$$). It's guaranteed that $$$p$$$ is an odd prime.
One integer — the answer.
11 3 8
3
998244353 11451400 919810000
454174074
96311898227 25437319919 55129361817
14846091352
Slitherlink is a puzzle game played on a $$$n \times n$$$ grid. Some cells of the grid contain numbers (called clues). The solver must draw lines along the edges of some cells to form a loop, such that:
Example Problem
Solution Construct a $$$n \times n$$$ slitherlink problem with full clues but multiple solutions. Moreover, there must be a pair of different solutions that satisfy all clues but share at most four edges.
Note: "full clues" means every cell in the problem should be filled with a clue number from $$$0,\ldots,4$$$. "Two solutions share $$$x$$$ edges" means that exactly $$$x$$$ edges appear in both solutions.
In the first line, $$$n$$$ ($$$2\leq n \leq 20$$$). It is guaranteed that an answer always exists.
First, output an $$$n \times n$$$ matrix — the problem.
Then, output two solutions — two $$$n \times n$$$ matrices. For each cell, if it is inside the loop, output "1", otherwise output "0".
5
2 2 2 1 2 2 2 3 1 1 2 2 2 1 1 3 2 3 3 2 1 0 1 1 3 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The example just shows how to output the problem and solutions. It will get a Wrong Answer verdict. These two solutions share $$$9$$$ edges and the second solution doesn't satisfy all clues.
You are given a directed graph with $$$n$$$ vertices and $$$m$$$ edges. You want to answer $$$q$$$ queries.
For each query, you are given $$$k_1, p_1,p_2, \dots, p_{k_1}$$$, $$$k_2, s_1, t_1, s_2, t_2, \dots, s_{k_2}, t_{k_2}$$$. For all $$$i$$$ ($$$1 \leq i \leq k_2$$$), answer whether there is a path from $$$s_i$$$ to $$$t_i$$$ if $$$p_1, p_2, \dots, p_{k_1}$$$ are deleted. Queries are independent.
In the first line, $$$n, m$$$ ($$$1\leq n\leq 500, 0\leq m \leq n(n-1)$$$).
In the following $$$m$$$ lines, $$$u, v$$$ ($$$1\leq u, v\leq n, u\neq v$$$) — a directed edge in the graph. It's guaranteed that there is no parallel edges.
In the next line, $$$q$$$ ($$$1\leq q \leq 4\times 10^5$$$). To make sure you answer the queries online, the input is encrypted. The input can be decrypted using the following pseudocode:
cnt = 0
for i = 1 ... q
read(k1)
for j = 1 ... k1
read(p'[j])
p[j] =(p'[j] + cnt - 1) read(k2)
for j = 1 ... k2
read(s', t')
s = (s' + cnt - 1) t = (t' + cnt - 1) cnt += query(s, t)
// if s can reach t, query return 1, otherwise, query return 0
In the following $$$2q$$$ lines, for each query:
For each query, output a binary string with length $$$k_2$$$ — the answer of query(s, t) in order.
5 4 1 2 2 3 3 4 4 5 2 1 4 2 1 5 1 3 3 5 3 4 1 1 2
01 1
It's recommended to use Fast IO.
You are given a sequence of nonnegative integers $$$a_1, a_2, \ldots, a_n$$$. You can perform the following three types of operations any number of times.
Output the minimum number of operations to make all numbers equal to $$$0$$$.
In the first line, $$$T$$$ ($$$1\leq T \leq 10$$$) — the number of test cases.
For each test case:
For each test case, one integer — the answer.
3 5 2 1 2 1 2 8 1000000000 1000000000 0 1000000000 \ 1000000000 0 1000000000 1000000000 (There won’t be extra line breakers \ in the actual test cases.) 13 1 1 4 5 1 4 1 9 1 9 8 1 0
2 3000000000 19
You are given $$$n$$$ intervals $$$[l_i, r_i]$$$. You want to build a graph with $$$n$$$ vertices, where the $$$i$$$-th vertex corresponds to the $$$i$$$-th interval. If two intervals $$$i, j$$$ intersect, add an undirected, unweighted edge between vertices $$$i$$$ and $$$j$$$.
Let $$$d(i, j)$$$ be the length of the shortest path between the $$$i$$$-th vertex and the $$$j$$$-th vertex. If there is no path from $$$i$$$ to $$$j$$$, $$$d(i, j) = 0$$$.
For $$$i = 1, 2, \dots, n$$$, output $$$\sum_{j=1}^n d(i, j)$$$.
In the first line, $$$n$$$ ($$$1\leq n\leq 2\times 10^5$$$).
In the following $$$n$$$ lines, $$$l_i, r_i$$$ ($$$1\leq l_i \lt r_i\leq 2n$$$). It's guaranteed that the endpoints of intervals are distinct.
$$$n$$$ lines, the answer of $$$i = 1, 2, \dots, n$$$.
5 2 3 6 7 1 9 5 10 4 8
7 5 4 5 5
You are given a grid graph with $$$n$$$ rows and $$$m$$$ columns. Most edges are directed, which means you can walk from $$$(x, y)$$$ to $$$(x + 1, y)$$$ or $$$(x, y + 1)$$$. $$$k$$$ horizontal edges are bidirectional, which means you can walk from $$$(x, y)$$$ to $$$(x, y + 1)$$$, and $$$(x, y + 1)$$$ to $$$(x, y)$$$ too. It's guaranteed that there is no pair of bidirectional edges that share an endpoint.
You need to find $$$l$$$ vertex-disjoint simple paths, where the $$$i$$$-th is from $$$(1, a_i)$$$ to $$$(n, b_i)$$$. For a set of paths, we call a bidirectional edge bad if neither of its endpoints is visited by any of the paths in this set.
Output the number of all $$$l$$$ vertex-disjoint simple paths without any bad edges, modulo $$$998244353$$$.
In the first line, $$$n, m, l, k$$$ ($$$2\leq n, m\leq 100, 1\leq l\leq 50, 0\leq k\leq 50$$$).
In the second line, $$$a_1, a_2, \dots, a_l$$$ ($$$1\leq a_1 \lt a_2 \lt \dots \lt a_l \leq m$$$).
In the third line, $$$b_1, b_2, \dots, b_l$$$ ($$$1\leq b_1 \lt b_2 \lt \dots \lt b_l \leq m$$$).
In the following $$$k$$$ lines, $$$x_i, y_i$$$ ($$$1\leq x_i \leq n, 1 \leq y_i \lt m$$$) each line, which denote that the edge $$$(x_i, y_i)$$$ to $$$(x_i, y_i + 1)$$$ is bidirectional.
It's guaranteed that there is no pair of bidirectional edges that share an endpoint.
One integer — the answer.
2 2 1 2 2 1 1 1 2 1
2
3 4 2 1 1 4 1 4 2 2
0
10 10 3 4 1 2 3 8 9 10 2 3 2 5 4 6 7 8
388035318
You are given $$$2^k - 1$$$ numbers $$$c_1, c_2, \dots, c_{2^k-1}$$$ and $$$k$$$ numbers $$$a_0 ,a_1, \dots a_{k-1}$$$.
You want to find nonnegative integers $$$x_1, x_2, \dots, x_{2^k-1}$$$ such that for all $$$j$$$ $$$(0\leq j \lt k)$$$ $$$$$$\sum_{i=1}^{2^k - 1} \left(\lfloor i / 2 ^j \rfloor \bmod 2\right) x_i = a_j$$$$$$ holds and $$$\sum_{i=1}^{2^k - 1}x_i c_i$$$ is maximized.
In the first line, $$$T$$$ ($$$1\leq T\leq 100$$$) — the number of test cases.
For each test case:
For each test case, one integer — the answer.
3 2 1 2 4 4 5 3 3226252 19270256 2430652 1187613 \ 12496062 10286165 17494834 24 85 34 4 901133 6693218 13245489 14740234 \ 16186210 11382783 19277321 3855635 \ 16523184 10168517 16195031 971041 \ 10303441 8395899 11618555 (There won't be extra line breakers \ in the actual test cases.) 529321239 218214127 92942310 207467810
18 1949753378 7832404777567179
We call two permutations $$$p_1, p_2, \dots, p_n$$$ and $$$q_1, q_2, \dots, q_n$$$ equivalent if and only if for every pair $$$(i, j)$$$ ($$$1\leq i \leq j \leq n$$$), the indices of the minimum element of $$$p_i, p_{i+1}, \dots, p_j$$$ and $$$q_i, q_{i+1}, \dots, q_j$$$ are the same.
Given $$$x$$$ and $$$y$$$, consider the set of all permutations $$$p$$$ of $$$\{1, 2, \ldots, n\}$$$ such that $$$p_x = y$$$. Find the maximum number of permutations you can pick from this set such that no two are equivalent. Output this number modulo $$$998244353$$$.
The problem is too easy, so output the answer for every $$$y = 1, 2, \dots, n$$$.
In the first line $$$n, x$$$ ($$$1\leq n \leq 5\times 10^5, 1\leq x \leq n$$$).
$$$n$$$ lines, answers for $$$y = 1, 2, \dots, n$$$.
5 2
5 10 16 20 14
10 5
588 1176 2716 4942 7407 9101 9636 9167 7596 4862