abc470
A - Fizz
模拟
B - Monocolor
Problem Statement
There are \(N\) balls. Each ball is painted in one of \(N\) colors: color \(1\) through color \(N\). The color of the \(i\)-th ball \((1\le i\le N)\) is \(C_i\).
In one operation, you can change the color of any one ball to any of the \(N\) colors.
Find the minimum number of operations required to make all the balls the same color.
Constraints
- \(1\le N\le 100\)
- \(1\le C_i\le N\)
- All input values are integers.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
C - Inc, Dec, Xor
Problem Statement
There is a length-\(N\) integer sequence \(A=(A_1,A_2,\ldots,A_N)\). Initially, all elements of \(A\) are \(0\).
You will be given \(Q\) queries, which should be processed in order. There are two types of queries, each given in one of the following formats:
1 x: Increase the value of \(A_x\) by \(1\).2: For each \(i=1,2,\ldots,N\), if \(A_i \geq 1\), decrease the value of \(A_i\) by \(1\).
Find the bitwise \(\mathrm{XOR}\) of \(A_1,A_2,\ldots,A_N\) immediately after processing each query.
What is bitwise \(\mathrm{XOR}\)?
The bitwise \(\mathrm{XOR}\) of non-negative integers \(A\) and \(B\), denoted \(A \oplus B\), is defined as follows:
- In the binary representation of \(A \oplus B\), the digit in the \(2^k\) (\(k \geq 0\)) place is \(1\) if exactly one of the digits in the \(2^k\) place of \(A\) and \(B\) in their binary representations is \(1\), and \(0\) otherwise.
For example, \(3 \oplus 5 = 6\) (in binary: \(011 \oplus 101 = 110\)).
More generally, the bitwise \(\mathrm{XOR}\) of \(k\) non-negative integers \(p_1, p_2, p_3, \dots, p_k\) is defined as \((\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)\), and it can be proved that this value does not depend on the order of \(p_1, p_2, p_3, \dots, p_k\).
Constraints
- \(1\le N\le 5\times 10^5\)
- \(1\le Q\le 5\times 10^5\)
- \(1\le x\le N\)
- All input values are integers.
Code
暴力模拟做法(不能AC,会超时)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
D - Inverse and Swap
Problem Statement
You are given a permutation \(P = (P_1, \dots, P_N)\) of \((1, \dots, N)\).
Process \(Q\) queries in order. There are two types of queries as follows:
1 x y: Swap the values of \(P_x\) and \(P_y\).2: Construct the permutation \(P' = (P'_1, \dots, P'_N)\) of \((1, \dots, N)\) satisfying the following condition, and replace the values of \(P_1, \dots, P_N\) with \(P'_1, \dots, P'_N\), respectively. (One can prove that such \(P'\) uniquely exists.)- \(P_{P'_i} = i\) for every integer \(i\) satisfying \(1 \leq i \leq N\).
Output the values of \(P_1, \dots, P_N\) after processing all queries.
Constraints
- \(2 \leq N \leq 5 \times 10^5\)
- \(1 \leq Q \leq 5 \times 10^5\)
- \((P_1, \dots, P_N)\) is a permutation of \((1, \dots, N)\).
- \(1 \leq x < y \leq N\) for queries of type \(1\).
- All input values are integers.
Code
暴力模拟(会超时)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |