CF1495E Qingshan and Daniel
Description
Qingshan and Daniel are going to play a card game. But it will be so boring if only two persons play this. So they will make $ n $ robots in total to play this game automatically. Robots made by Qingshan belong to the team $ 1 $ , and robots made by Daniel belong to the team $ 2 $ . Robot $ i $ belongs to team $ t_i $ . Before the game starts, $ a_i $ cards are given for robot $ i $ .
The rules for this card game are simple:
- Before the start, the robots are arranged in a circle in the order or their indices. The robots will discard cards in some order, in each step one robot discards a single card. When the game starts, robot $ 1 $ will discard one of its cards. After that, robots will follow the following rules:
- If robot $ i $ discards the card last, the nearest robot whose team is opposite from $ i $ 's will discard the card next. In another word $ j $ will discard a card right after $ i $ , if and only if among all $ j $ that satisfy $ t_i\ne t_j $ , $ dist(i,j) $ (definition is below) is minimum.
- The robot who has no cards should quit the game immediately. This robot won't be considered in the next steps.
- When no robot can discard the card next, the game ends.
We define the distance from robot $ x $ to robot $ y $ as $ dist(x,y)=(y-x+n)\bmod n $ . It is similar to the oriented distance on the circle.
For example, when $ n=5 $ , the distance from $ 1 $ to $ 3 $ is $ dist(1,3)=(3-1+5)\bmod 5=2 $ , the distance from $ 3 $ to $ 1 $ is $ dist(3,1)=(1-3+5)\bmod 5 =3 $ .
Later, Qingshan finds out that it will take so much time to see how robots play. She wants to know the result as quickly as possible. You, as Qingshan's fan, are asked to calculate an array $ [ans_1,ans_2,\ldots,ans_n] $ — $ ans_i $ is equal to the number of cards, that $ i $ -th robot will discard during the game. You need to hurry!
To avoid the large size of the input, the team and the number of cards of each robot will be generated in your code with some auxiliary arrays.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first test case $ a=[5,5,1] $ and $ t=[1,2,2] $ .
The robot $ 1 $ discards the card first.
Then robot $ 2 $ discards the card next. Robot $ 3 $ doesn't discard the card next because $ dist(1,2)