CT54413

Jaya's Disorder Count Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the railway depot of Cinderline, Jaya records each weights in a worn leather ledger. The guild wants answers, not guesses. 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 <= 2375; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 1057 436462 -107150 793884 -579975 -32138 -544691 -451189 -817342 -84046 -623902 481354 625845 463277 739658 -355491 10188 -651066 -549301 -806645 856000 717971 -479943 298535 714454 948488 -997976 733504 -946241 -533545 711176 -61875 -215650 632344 -595755 802861 -681824 -4338 -952520 -725140 -392820 -887949 -384883 946806 -306657 -891647 998038 937864 -182043 -35999 928743 814400 719318 21771 589252 725688 -911921 172570 -205159 88686 444057 140017 892784 -210122 247571 854031 190319 368648 -125774 457536 -102023 514963 -796070 -886127 -27126 -62900 97261 -132066 -742004 264756 -557389 -80446 723996 434969 414296 -58877 -529262 -620613 -619621 14764 -312205 235911 51776 390896 -844607 -315368 71957 937211 926176 -745760 79793 -555406 -950736 315880 -234576 158976 379414 120086 -991349 24…
Output: 278606

Example 2:

Input: 495 -333985 -282700 -268360 133685 -927704 973604 907446 -283106 772212 583974 -829469 434536 178256 316331 -996627 -361994 952125 618611 -615969 85724 -774905 686797 -10271 407120 333737 -680451 237280 -1019 857658 252769 61632 66712 -363400 -925383 278441 109377 -48278 -176838 -776363 -338342 -549907 578724 -176388 -512002 -333408 732820 841877 -144592 -647264 655132 654957 -225939 471092 765549 741501 887359 341133 -263896 699473 333282 -95926 957799 892739 -213960 -835711 -330107 248694 -187436 84170 320110 696672 146745 340172 -586868 909637 -192504 682480 465527 769322 -906429 -912427 255773 -385022 -464473 -160199 -62302 418350 583013 931287 -69919 475312 166242 353570 91795 974498 -121597 785781 300941 -993170 -483538 -135200 2072 -332818 -757906 -911684 634202 -527745 621039 -9144…
Output: 60379

Example 3:

Input: 305 568933 122264 -921788 -551628 98405 951278 -756000 -988331 -444502 -64969 550416 615315 -477709 569624 398713 873371 -29795 -889322 -315446 182648 -172468 -489907 -188096 896102 1351 -754947 907944 559134 885191 353640 -965356 -246875 -547666 -847115 -575977 930351 -636405 -607071 -706523 -641027 325803 -985415 -791185 -260034 -581684 123337 -453981 989742 973810 -636323 -683646 629976 750617 -522565 -735314 115173 -71013 164372 -792613 -80662 359423 -102168 -920546 -11471 341357 -300936 48409 695599 271228 -385366 -638594 60865 -464680 -195461 439716 138117 -483838 -23339 -250517 767191 91698 888877 605878 -241917 -292524 991659 -943120 -264101 -985194 517153 387596 -300664 -705603 -681920 272395 403865 -403496 -454383 791714 805424 604073 357935 -302494 2652 355091 -583980 106984 280…
Output: 22065

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.