CT47940

Yusuf's Crimson registers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the honey farms of Buzzwell as Yusuf unrolls the day's manifest of registers. The tally will decide the next shipment. 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 <= 2472; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 2070 -740531 -954636 478010 478066 -410212 -820180 -249823 -357774 695938 927008 359182 -754136 -9774 736480 -17048 8129 747414 581294 -345426 -985214 309068 -565222 983848 250892 -667648 -856167 -595531 478364 -377698 -154279 777818 -720473 47328 936113 32931 -461888 -929694 630630 -613190 -913 901338 141503 -364058 -64093 871210 243259 -436531 -261234 -998043 947048 -228512 127883 -466687 -436336 816817 102586 -235380 411523 -488124 -481130 411843 609405 -106354 -229124 158943 170296 -450172 -960512 989675 -482381 750003 -126811 734161 -154539 694339 595839 858589 865647 -322557 91419 -700702 -958284 -473915 392552 138365 645908 -71808 281847 -478461 -370579 -237351 -979252 -490714 -411809 366675 -820728 705417 -21426 104544 -233911 432866 459658 -668973 441334 -896022 -367241 -677467 -3…
Output: 1053841

Example 2:

Input: 2102 -802752 -202520 -434082 -851166 -728766 312194 136822 -821029 855086 116072 -294501 -858213 974031 114110 -85045 307181 970351 -857675 354153 973529 -960995 96248 -647904 848953 -610203 -603215 52653 -364674 858071 -396635 -75877 296378 744316 -868184 166428 974785 -328928 468324 735480 -272755 -844046 133294 -877815 358659 818600 -205510 650947 1048 410345 -834749 -112616 807573 -211056 -75850 244476 507657 403610 -452152 648934 437306 -646729 274447 56401 998769 710524 792463 364054 759081 764230 868524 147651 750761 -664122 -881964 -982787 847753 -603937 724598 838190 -881351 -359691 -41097 -406816 -190817 -152214 828128 958240 869766 -997814 693874 583411 -236949 98632 -457774 759163 988953 343148 702938 -857802 275092 -207099 -607394 781804 696246 195552 -409806 293864 840882 877…
Output: 1117839

Example 3:

Input: 1847 263135 84437 942555 -526607 -715240 26878 -162890 -895157 703896 444448 184392 -464275 715052 -814264 -766573 -529469 -840489 686257 410494 76840 -78335 -182306 747334 157597 -303592 -908507 -363532 -931671 497632 -14260 896390 143496 -840633 572123 -391696 -170208 -857860 -211681 643109 589405 68350 260337 -912251 -241323 850326 31671 157455 125384 -514915 -601374 455222 510992 23626 962468 554628 -649027 603225 868026 -111348 -813926 -349378 941771 -92931 -44238 -104390 958363 47752 4771 834602 -940306 313077 -879554 658071 -651380 -14400 -651889 -715030 728346 96546 -886102 -17971 -408033 -484660 594612 869711 -297100 -143128 -883642 554408 -928936 894403 -855834 -235946 -696322 -355144 -816198 927005 151189 -850097 -48628 -333133 998969 -652156 -149279 167422 49266 793974 485279 -…
Output: 839910

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Yusuf's Crimson registers - MEDIUM Coding Problem | CodeTikki