Editorial for A2SV Education Phase I — Contest #6

Revision en13, by nuredinbederu10k, 2025-03-10 18:27:45

B. Thousand Sunny's Network Setup

Solution
Code

D. Pirates Island: Painting the Grand Line

Solution
Code

E. Straw Hat's Blue-Red Permutation

Solution

Now consider separately two red numbers $$$a_{i}$$$ and $$$a_{j}$$$ such that $$$a_{i} \gt a_{j}$$$ . If $$$x$$$ is produced by increasing $$$a_{i}$$$ and $$$y$$$ is produced by increasing $$$a_{j}$$$ , and in the same time $$$x \lt y$$$ then $$$y \gt x⩾a_{i} \gt a_{j}$$$ , and the following is also true: $$$x \gt a_{j}$$$ and $$$y \gt a_{i}$$$ . So we just showed that if an answer exists, it also exists if greater numbers are produced by greater values from the input. The same holds for the blue numbers.

Let us sort all elements ai by the key $$$(c_{i},a_{i})$$$ , where $$$c_{i}$$$ the color of $$$i-th$$$ element (and blue comes before red). It remains to check that for any $$$t$$$ from $$$1$$$ to $$$n$$$ we can get the number $$$t$$$ from the $$$t$$$ -th element of the obtained sorted array. To do this, we iterate through it and check that either $$$c_{t}='B'$$$ and $$$a_{t}⩾t$$$ so it can be reduced to $$$t$$$, or, symmetrically, $$$c_{t}='R'$$$ and $$$a_{t}⩽t$$$. <\spoiler>

Code

F. Luffy’s Lineup Challenge

Solution

Code


from collections import defaultdict n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) hash_map = defaultdict(list) for i in range(n): hash_map[a[i]].append(i) for i in range(n): temp = hash_map[b[i]].pop() b[i] = temp swaps = [] swap_count = 0 while True: swapped = False for i in range(n - 1): if b[i] > b[i + 1]: b[i], b[i + 1] = b[i + 1], b[i] swaps.append((i + 1, i + 2)) swap_count += 1 swapped = True if not swapped: break print(swap_count) for swap in swaps: print(swap[0], swap[1])

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en39 English nuredinbederu10k 2025-04-28 10:54:11 167 Reverted to en37
en38 English nuredinbederu10k 2025-03-12 12:00:13 167
en37 English nuredinbederu10k 2025-03-12 11:50:56 2132
en36 English nuredinbederu10k 2025-03-12 11:35:36 2044
en35 English nuredinbederu10k 2025-03-12 11:28:21 83
en34 English nuredinbederu10k 2025-03-12 11:26:09 1307
en33 English nuredinbederu10k 2025-03-12 11:19:44 768
en32 English nuredinbederu10k 2025-03-12 11:18:07 732
en31 English nuredinbederu10k 2025-03-12 11:15:54 2128
en30 English nuredinbederu10k 2025-03-12 11:14:22 6 Tiny change: 'ode">\n```python\nt = int(' -> 'ode">\n```\nt = int('
en29 English nuredinbederu10k 2025-03-12 11:11:13 2096
en28 English nuredinbederu10k 2025-03-12 10:56:48 1602
en27 English nuredinbederu10k 2025-03-12 10:54:48 3936 Tiny change: 'plit()))\n \n \ndef next' -> 'plit()))\ndef next'
en26 English nuredinbederu10k 2025-03-12 10:45:23 13
en25 English nuredinbederu10k 2025-03-12 10:43:22 507
en24 English nuredinbederu10k 2025-03-11 09:35:07 239
en23 English nuredinbederu10k 2025-03-11 09:33:44 450
en22 English nuredinbederu10k 2025-03-11 09:32:11 804
en21 English nuredinbederu10k 2025-03-11 09:30:47 12
en20 English brooksolo 2025-03-10 20:45:26 726
en19 English devAsher 2025-03-10 19:48:11 928
en18 English nuredinbederu10k 2025-03-10 18:40:12 12
en17 English nuredinbederu10k 2025-03-10 18:37:33 14
en16 English nuredinbederu10k 2025-03-10 18:35:46 286
en15 English nuredinbederu10k 2025-03-10 18:31:05 26
en14 English nuredinbederu10k 2025-03-10 18:29:10 4 Tiny change: 'positions.Once we ha' -> 'positions.\n\nOnce we ha'
en13 English nuredinbederu10k 2025-03-10 18:27:45 84
en12 English nuredinbederu10k 2025-03-10 18:21:06 1802
en11 English nuredinbederu10k 2025-03-10 18:07:06 18 Tiny change: 'lem/E)\n\n==================\n<spoiler' -> 'lem/E)\n\n\n<spoiler'
en10 English nuredinbederu10k 2025-03-10 17:45:52 8
en9 English nuredinbederu10k 2025-03-10 17:40:39 111
en8 English nuredinbederu10k 2025-03-10 17:29:21 850 (published)
en7 English mulugetasolomonabate 2025-03-10 17:05:19 2981
en6 English FunkyLlama 2025-03-10 16:13:22 1620 Tiny change: 'olor of $i$\n-th element (' -> 'olor of $i-th$ element (' (saved to drafts)
en5 English nuredinbederu10k 2025-03-10 12:55:34 29 Tiny change: '\n\n<spoiler' -> '[problem:Some Random Problem]\n<spoiler'
en4 English nuredinbederu10k 2025-03-10 12:54:05 15
en3 English nuredinbederu10k 2025-03-10 12:53:12 100
en2 English nuredinbederu10k 2025-03-10 11:35:27 19 Tiny change: 'Hello' -> 'Moshi Mosh !!!'
en1 English nuredinbederu10k 2025-03-10 11:31:50 54 Initial revision (published)