补题链接:https://codeforces.com/gym/103470
Oops, It’s Yesterday Twice More
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
After the great success in 2018, 2019, and 2020, Nanjing University of Aeronautics and Astronautics
(NUAA) will host the International Collegiate Programming Contest (ICPC) Nanjing regional for the
fourth time.
Team Power of Two and team Three Hold Two won the champion for Tsinghua University in 2018
and 2019. In 2020, team Inverted Cross from Peking University won the champion. In 2021, there are
around 700 teams including the defending champion participating in the contest. We are so excited
to see who will win this year!
Although we can’t gather in Nanjing this time due to the pandemic, we should still be grateful for the
hard work done by all staff and volunteers for this contest. Thank you all for your great contribution to
this contest!
In the 2018 contest, problem K, Kangaroo Puzzle, requires the contestants to construct an operation
sequence for the game:
The puzzle is a grid with n rows and m columns (1 ≤ n, m ≤ 20) and there are some (at least 2)
kangaroos standing in the puzzle. The player’s goal is to control them to get together. There are some
walls in some cells and the kangaroos cannot enter the cells with walls. The other cells are empty. The
kangaroos can move from an empty cell to an adjacent empty cell in four directions: up, down, left, and
right.
There is exactly one kangaroo in every empty cell in the beginning and the player can control the
kangaroos by pressing the button U, D, L, R on the keyboard. The kangaroos will move simultaneously
according to the button you press.
The contestant needs to construct an operating sequence of at most 5 × 104
steps consisting of U, D, L,
R only to achieve the goal.
In the 2020 contest, problem A, Ah, It’s Yesterday Once More, requires the contestants to construct
an input map to hack the following code of the problem described before:
#include
using namespace s t d ;
s t r i n g s = “UDLR” ;
int main ( )
{
s rand ( time (NULL ) ) ;
for ( int i = 1 ; i <= 50000; i++) pu tcha r ( s [ rand ( ) % 4 ] ) ;
return 0 ;
}
Now in the 2021 contest, Paimon prepares another version of the problem for you. You are given a grid
with n rows and n columns (2 ≤ n ≤ 500). All cells are empty and there is one kangaroo standing in each
cell.
Similarly, you can control the kangaroos by pressing the button U, D, L, R on the keyboard. The kangaroos
will move simultaneously according to the button you press. Specifically, for any kangaroo located in the
cell on the i-th row and the j-th column, indicated by (i, j):
题目
思路:
#include
using namespace std;
const int maxn = 1010;
int main(){int n, a, b; cin>>n>>a>>b;int up = 0, dy = 0; //往上int le = 0, dx = 0; //往左if(a <= n/2){up = 1; dy = a-1;for(int i = 1; i < n; i++)cout<<"U";}else{up = 0; dy = n-a;for(int i = 1; i < n; i++)cout<<"D";}if(b <= n/2){le = 1; dx = b-1;for(int i = 1; i < n; i++)cout<<"L";}else{le = 0; dx = n-b;for(int i = 1; i < n; i++)cout<<"R";}if(up==1)for(int i = 1; i <= dy; i++)cout<<"D";else for(int i = 1; i <= dy; i++)cout<<"U";if(le==1)for(int i = 1; i <= dx; i++)cout<<"R";else for(int i = 1; i <= dx; i++)cout<<"L";return 0;
}
M. Windblume Festival
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
The Windblume Festival in Mondstadt is coming! People are preparing windblumes for Barbatos and for those they love and adore. The Windblume Festival is also an opportunity to improve the relationships people have.
Source: Genshin Impact Official
During the festival, a famous game will be played every year, invented by Jean, the Acting Grand Master of the Knights of Favonius. In the game, n players numbered from 1 to n stand in a circle, each holding an integer with them. Each turn, one player will be removed. The game will end when there is only one player left.
For each turn, let k be the number of players remaining and ai be the integer player i holds. Two adjacent players, x and (xmodk+1) are selected and player (xmodk+1) is removed from the game. Player x’s integer will then change from ax to (ax−axmodk+1). Player y in this turn will become player (y−1) in the next turn for all x Jean wants to know the maximum possible integer held by the last remaining player in the game by selecting the players in each round optimally. Input The first line contains one integer n (1≤n≤106) indicating the initial number of players. The next line contains n integers ai (−109≤ai≤109) where ai is the integer held by player i at the beginning. It is guaranteed that the sum of n of all test cases will not exceed 106. Output Example {1–,−3,2,−4–––} (select x=4) → {−3,2,−5–––––} (select x=2) → {−3,7–––––} (select x=2) → {10}. 题目 思路: C. Klee in Solitary Confinement Source: Genshin Impact Official Being sent to solitary confinement by Jean again, Klee decides to spend time learning the famous Mo’s algorithm, which can compute with a time complexity of O(n1.5) for some range query problem without modifications. To check whether Klee has truly mastered the algorithm (or in fact making another bombs secretly), Jean gives her a problem of an integer sequence a1,a2,⋯,an along with some queries [li,ri] requiring her to find the mode number in the contiguous subsequence ali,ali+1,⋯,ari. The mode number is the most common number (that is to say, the number which appears the maximum number of times) in the subsequence. With the help of Mo’s algorithm, Klee solves that problem without effort, but another problem comes into her mind. Given an integer sequence a1,a2,⋯,an of length n and an integer k, you can perform the following operation at most once: Choose two integers l and r such that 1≤l≤r≤n and add k to every ai where l≤i≤r. Note that it is OK not to perform this operation. Compute the maximum occurrence of the mode number of the whole sequence if you choose to perform (or not perform) the operation optimally. Input The first line of the input contains two integers n and k (1≤n≤106, −106≤k≤106) indicating the length of the sequence and the additive number. The second line of the input contains n integers a1,a2,⋯,an (−106≤ai≤106) indicating the original sequence. Output Examples For the second sample test case, choose l=4 and r=6 and we’ll result in the sequence {3,2,3,3,3,3,3}. The mode number is 3 which appears 6 times. For the fourth sample test case, choose not to perform the operation. The mode number is 1 and −2 which both appear 3 times. 题目 思路: H. Crystalfly Pixiv ID: 93964680 There are initially ai crystalflies on the i-th vertex. When Paimon reaches a vertex, she can catch all the remaining crystalflies on the vertex immediately. However, the crystalflies are timid. When Paimon reaches a vertex, all the crystalflies on the adjacent vertices will be disturbed. For the i-th vertex, if the crystalflies on the vertex are disturbed for the first time at the beginning of the t′-th second, they will disappear at the end of the (t′+ti)-th second. At the beginning of the 0-th second, Paimon reaches vertex 1 and stays there before the beginning of the 1-st second. Then at the beginning of each following second, she can choose one of the two operations: Move to one of the adjacent vertices of her current vertex and stay there before the beginning of the next second (if the crystalflies in the destination will disappear at the end of that second she can still catch them). Input The first line contains an integer n (1≤n≤105) indicating the number of vertices. The second line contains n integers a1,a2,⋯,an (1≤ai≤109) where ai is the number of crystalflies on the i-th vertex. The third line contains n integers t1,t2,⋯,tn (1≤ti≤3) where ti is the time before the crystalflies on the i-th vertex disappear after disturbed. For the next (n−1) lines, the i-th line contains two integers ui and vi (1≤ui,vi≤n) indicating an edge connecting vertices ui and vi in the tree. It’s guaranteed that the sum of n of all the test cases will not exceed 106. Output Example During the 0-th second 题目 思路: Paimon Sorting 题目 思路:
There are multiple test cases. The first line of the input contains one integer T indicating the number of test cases. For each test case:
For each test case output one line containing one integer indicating the maximum possible integer.
inputCopy
5
4
1 -3 2 -4
11
91 66 73 71 32 83 72 79 84 33 93
12
91 66 73 71 32 83 72 79 84 33 33 93
13
91 66 73 71 32 83 72 79 84 33 33 33 93
1
0
outputCopy
10
713
746
779
0
Note
For the first sample test case follow the strategy shown below, where the underlined integers are the integers held by the players selected in each turn.#include
C.Klee in Solitary Confinement
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Since the traveler comes, People in Monstadt suddenly raise great interest in computer programming and algorithms, including Klee, the Spark Knight of the Knights of Favonius.
There is only one test case in each test file.
Output one line containing one integer indicating the maximum occurrence of the mode number of the whole sequence after performing (or not performing) the operation.
inputCopy
5 2
2 2 4 4 4
outputCopy
5
inputCopy
7 1
3 2 3 2 2 2 3
outputCopy
6
inputCopy
7 1
2 3 2 3 2 3 3
outputCopy
5
inputCopy
9 -100
-1 -2 1 2 -1 -2 1 -2 1
outputCopy
3
Note
For the first sample test case, choose l=1 and r=2 and we’ll result in the sequence {4,4,4,4,4}. The mode number is obviously 4 which appears 5 times.#include
H.Crystalfly
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Paimon is catching crystalflies on a tree, which are a special kind of butterflies in Teyvat. A tree is a connected graph consisting of n vertices and (n−1) undirected edges.
Stay still in her current vertex before the beginning of the next second.
Calculate the maximum number of crystalflies Paimon can catch in 1010101010 seconds.
There are multiple test cases. The first line of the input contains an integer T indicating the number of test cases. For each test case:
For each test case output one line containing one integer indicating the maximum number of crystalflies Paimon can catch.
inputCopy
2
5
1 10 100 1000 10000
1 2 1 1 1
1 2
1 3
2 4
2 5
5
1 10 100 1000 10000
1 3 1 1 1
1 2
1 3
2 4
2 5
outputCopy
10101
10111
Note
For the first sample test case, follow the strategy below.
Paimon arrives at vertex 1;
Paimon catches 1 crystalfly;
Crystalflies in vertices 2 and 3 are disturbed.
During the 1-st second
Paimon arrives at vertex 3;
Paimon catches 100 crystalflies.
During the 2-nd second
Paimon arrives at vertex 1;
Crystalflies in vertex 2 disappears.
During the 3-rd second
Paimon arrives at vertex 2;
Crystalflies in vertices 4 and 5 are disturbed.
During the 4-th second
Paimon arrives at vertex 5;
Paimon catches 10000 crystalflies;
Crystalflies in vertex 4 disappears.
For the second sample test case, the optimal strategy is the same with the first sample test case. Crystalflies in vertex 2 are scheduled to disappear at the end of the 3-rd (instead of the 2-nd) second, allowing Paimon to catch them.
一种是进入某个儿子 v 后继续向下,这样 x 的所有其它儿子的蝴蝶都无法被获取。
另一种是进入某个儿子 v 获取 av 后立即回到 x,然后进入另一个儿子 w 并获得 aw ,这要求 tw=3。
第一种决策:f[u] = sum[u]+max{a[v]}, 从v走下去
第二种决策:f[u] = sum[u]-f[v]+sum[v]+a[v]+max{a[v0], v0!=v, v==3}, 拿一个除了v最大的, 再从v走下去,v需要==3#include
D.Paimon Sorting
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
Paimon just invents a new sorting algorithm which looks much like bubble sort, with a few differences. It
accepts a 1-indexed sequence A of length n and sorts it. Its pseudo-code is shown below.
Algorithm 1 The Sorting Algorithm
1: function Sort(A)
2: for i ← 1 to n do . n is the number of elements in A
3: for j ← 1 to n do
4: if ai < aj then . ai
is the i-th element in A
5: Swap ai and aj
6: end if
7: end for
8: end for
9: end function
If you don’t believe this piece of algorithm can sort a sequence it will also be your task to prove it. Anyway
here comes the question:
Given an integer sequence A = a1, a2, · · · , an of length n, for each of its prefix Ak of length k (that is, for
each 1 ≤ k ≤ n, consider the subsequence Ak = a1, a2, · · · , ak), count the number of swaps performed if
we call SORT(Ak).
Input
There are multiple test cases. The first line of the input contains an integer T indicating the number of
test cases. For each test case:
The first line contains an integer n (1 ≤ n ≤ 105
) indicating the length of the sequence.
The second line contains n integers a1, a2, · · · , an (1 ≤ ai ≤ n) indicating the given sequence.
It’s guaranteed that the sum of n of all test cases will not exceed 106
.
Output
For each test case output one line containing n integers s1, s2, · · · , sn separated by a space, where si
is
the number of swaps performed if we call SORT(Ai).
Please, DO NOT output extra spaces at the end of each line or your solution may be considered incorrect!
Example
standard input standard output
3
5
2 3 2 1 5
3
1 2 3
1
1
0 2 3 5 7
0 2 4
0
Page 1 of 1
可以用树状数组维护,前面比当前元素大的数的个数(去重后)。
相等的元素是不会产生贡献的,因此vis去重特判掉即可。
若当前的非特殊元素a[i]等于上个特殊元素, 那么上个特殊元素会对该元素产生1的贡献,需要特判。
#include