CT44501

Hidden ledgers Disorder Count

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the cinnabar mines of Vermilion, Elsa studies rows of ledgers entries. One clean number will settle the guild's oldest argument. Task: Print the number of inversions: index pairs (i,j) with i<j but a[i] > a[j]. Input format: First line: n. Second line: n integers. Output format: Print the inversion count (fits 64-bit). Constraints: 1 <= n <= 2502; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 956 695659 -998247 625504 -76211 -329579 -77102 625518 554320 -551864 -389105 24264 69287 769611 489109 -712063 576480 -676581 -900935 -898368 545838 -891101 306210 -100754 -439859 -255572 -977106 -897453 -118924 -755691 -23648 -731793 -555287 938108 37345 401616 633664 948400 982952 -551451 -766513 -287744 -667312 -42376 -332390 304151 920176 -516036 -20696 497099 555049 -259759 103387 -849514 411080 -869082 68853 870026 -837557 567800 -518397 377509 -521062 277732 436329 658473 -967356 -532769 -482825 867645 925718 -621468 483914 976244 655984 524635 229707 -299862 706879 53333 -717863 -315129 221016 45461 -559028 -53697 275843 -214323 -755062 -888490 630503 -393354 769315 413242 358901 -144886 8424 -284458 -800904 882812 354829 -802315 -411382 -376831 -429235 25060 159806 -736865 -39297…
Output: 230320

Example 2:

Input: 686 603820 484010 349623 149465 291393 -789333 -149751 -528943 79387 721202 -28387 238795 -124778 -858030 591686 355988 712733 -288893 55880 7440 -717744 669715 -851936 -685595 -843785 -416533 -940343 463142 -58063 -811896 82979 252153 -93183 19171 -786295 584229 277952 -766987 -765169 215338 672321 -340103 -266505 -941944 -28453 44384 -462955 -36266 714519 62179 217698 -345305 567995 -781792 -611072 760843 293971 989031 970234 -793162 -42668 908977 -672141 121014 -402191 -621505 388515 220318 -799789 -517960 571174 605016 798362 -718446 145951 -620464 -359061 -142790 -315402 392525 266161 534520 -812091 985919 935393 589216 -873050 -535756 214369 -947948 555006 -430675 -725083 742599 -500264 534157 -108921 -267976 -659119 321868 70165 406097 -584649 811531 201846 326389 -45158 50211 96018…
Output: 117538

Example 3:

Input: 1149 -121295 -182167 -785248 -877198 -553319 -935158 600561 611488 -919558 -632173 370547 -778017 722377 -928877 465507 -148938 -392347 -973433 -725258 290200 402839 324889 -441434 -745011 681281 601570 -914995 400138 446817 904514 76482 585855 398351 -555809 448968 379030 -306632 765594 299096 837622 235186 -76124 -314553 -943566 -462990 515254 418080 102957 763244 890237 -142227 -660284 4792 991901 -189703 -529370 -282188 132196 772201 -742488 -901999 255307 -928621 121255 -201023 758422 -567732 -582535 -849191 -866473 -175029 574557 -787238 234428 486735 -241667 -320978 468114 580499 768641 584569 -941712 826959 -717443 733665 -774038 62003 174325 23455 241690 107853 57387 911485 326639 588546 -937760 917384 -121127 682613 513635 -797026 95147 -902009 614497 -179716 -973666 -675049 -793…
Output: 330357

Constraints:

1 <= n <= 2502; -1000000 <= a[i],x <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Hidden ledgers Disorder Count - MEDIUM Coding Problem | CodeTikki