Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
You are given an array (a), consisting of (n) integers (numbered from (1) to (n)). Initially, they are all zeroes. You have to process (q) queries. The (i)-th query consists of two different integers (x_i) and (y_i). During the (i)-th query, you have to choose an integer (p) (which is either (x_i) or (y_i)) and an integer (d) (which is either (1) or (-1)), and assign (a_p = a_p + d). After each query, every element of (a) should be a non-negative integer. Process all queries in such a way that the sum of all elements of (a) after the last query is the minimum possible. The first line contains two integers (n) and (q) ((2 \le n \le 3 \cdot 10^5); (1 \le q \le 3 \cdot 10^5)) — the number of elements in (a) and the number of queries, respectively. Then (q) lines follow. The (i)-th of these lines contains two integers (x_i) and (y_i) ((1 \le x_i, y_i \le n); (x_i \ne y_i)) — the description of the (i)-th query. For each query, print a line containing two characters: the first character should be x if you choose (p=x_i), or y if you choose (p=y_i); the second character should be + if you choose (d=1), or - if you choose (d=-1). If there are multiple answers, print any of them. |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
285934674 |
og.kostya |
F |
Oct. 14, 2024, 5:01 p.m. |
OK |
C# 10 |
TESTS |
49 |
952 |
93900800 |
|
|
|
285986235 |
liaoz123 |
F |
Oct. 15, 2024, 4:44 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
234 |
41164800 |
|
|
|
285937111 |
Xu_Hongxi |
F |
Oct. 14, 2024, 5:16 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
265 |
18124800 |
|
|
|
285942352 |
Roll_Num_44 |
F |
Oct. 14, 2024, 5:52 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
280 |
18432000 |
|
|
|
285930546 |
hswfwkj |
F |
Oct. 14, 2024, 4:41 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
311 |
18227200 |
|
|
|
285978441 |
PeruvianCartel |
F |
Oct. 15, 2024, 3:01 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
374 |
26112000 |
|
|
|
285923665 |
daaaaaaaaaaaaaaaaaaa |
F |
Oct. 14, 2024, 4:26 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
390 |
19968000 |
|
|
|
285985548 |
SuyashIIITIAN |
F |
Oct. 15, 2024, 4:36 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
405 |
40448000 |
|
|
|
285978912 |
JerryMao |
F |
Oct. 15, 2024, 3:09 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
405 |
70246400 |
|
|
|
285945463 |
ender_shayan |
F |
Oct. 14, 2024, 6:14 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
405 |
81715200 |
|
|
|
285953939 |
I_HATE_GEOMETRY |
F |
Oct. 14, 2024, 7:26 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
49 |
406 |
20377600 |
|
|
|
285992788 |
sunzz3183 |
F |
Oct. 15, 2024, 5:34 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
218 |
23244800 |
|
|
|
285932903 |
LOOP0 |
F |
Oct. 14, 2024, 4:52 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
249 |
50995200 |
|
|
|
285939614 |
shushhh |
F |
Oct. 14, 2024, 5:33 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
296 |
26112000 |
|
|
|
285983669 |
HypeTheTimeQuest |
F |
Oct. 15, 2024, 4:12 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
296 |
27852800 |
|
|
|
285974341 |
adam01 |
F |
Oct. 15, 2024, 1:51 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
327 |
33996800 |
|
|
|
285994588 |
Wael_Zaiback |
F |
Oct. 15, 2024, 5:52 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
343 |
25088000 |
|
|
|
285952156 |
mispertion20 |
F |
Oct. 14, 2024, 7:09 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
343 |
27545600 |
|
|
|
285977295 |
KingPowers |
F |
Oct. 15, 2024, 2:43 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
343 |
29491200 |
|
|
|
285980440 |
lucky_clover_ |
F |
Oct. 15, 2024, 3:29 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
343 |
57036800 |
|
|
|
285952857 |
PieArmy |
F |
Oct. 14, 2024, 7:16 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
49 |
358 |
22630400 |
|
|
|
285953480 |
TsukumoSama |
F |
Oct. 14, 2024, 7:22 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
265 |
26214400 |
|
|
|
285980197 |
am_25 |
F |
Oct. 15, 2024, 3:26 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
359 |
42496000 |
|
|
|
285923929 |
lcyxds |
F |
Oct. 14, 2024, 4:26 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
374 |
32358400 |
|
|
|
285964452 |
joaozao |
F |
Oct. 14, 2024, 9:45 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
389 |
30105600 |
|
|
|
285925943 |
busamate |
F |
Oct. 14, 2024, 4:30 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
389 |
39014400 |
|
|
|
285974333 |
Xiaohuba |
F |
Oct. 15, 2024, 1:51 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
421 |
29593600 |
|
|
|
285972395 |
Coder-Osman |
F |
Oct. 15, 2024, 1:10 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
421 |
31129600 |
|
|
|
285985836 |
F_Rio |
F |
Oct. 15, 2024, 4:39 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
421 |
36556800 |
|
|
|
285927354 |
ivatopuria |
F |
Oct. 14, 2024, 4:32 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
421 |
47411200 |
|
|
|
285927404 |
ivatopuria |
F |
Oct. 14, 2024, 4:32 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
49 |
436 |
47104000 |
|
|
|
285946634 |
-dub-otrezkov- |
F |
Oct. 14, 2024, 6:22 p.m. |
OK |
Go |
TESTS |
49 |
608 |
68710400 |
|
|
|
285943304 |
profchi |
F |
Oct. 14, 2024, 5:58 p.m. |
OK |
Java 8 |
TESTS |
49 |
1264 |
79974400 |
|
|
|
285951801 |
plevande |
F |
Oct. 14, 2024, 7:06 p.m. |
OK |
PyPy 3 |
TESTS |
49 |
2531 |
108851200 |
|
|
|
285925410 |
tassei903 |
F |
Oct. 14, 2024, 4:29 p.m. |
OK |
PyPy 3-64 |
TESTS |
49 |
1390 |
100249600 |
|
|
|
285937973 |
shuyefan |
F |
Oct. 14, 2024, 5:22 p.m. |
OK |
PyPy 3-64 |
TESTS |
49 |
2155 |
149299200 |
|
|
|
285968826 |
vwxyz0 |
F |
Oct. 14, 2024, 11:35 p.m. |
OK |
PyPy 3-64 |
TESTS |
49 |
2374 |
160665600 |
|
|
remove filters
Back to search problems