CT43433

Quinn's Brass Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Quinn inherited the chandlery at the wheat plains of Amberfield along with its curious bookkeeping system for registers. Time to make sense of it. 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 <= 2574; -1000000 <= a[i],x <= 1000000000.

Example 1:

Input: 72 339898102 531690534 154443989 332358955 592396493 964729159 403868945 729625472 797088269 789016077 292640402 458327293 843437331 380853331 434860261 886237306 428738890 484337298 434215036 748267889 555281335 645131012 474171685 430323916 776359698 146801627 764701870 138902301 741609910 171080778 910733688 710555657 8890062 910922204 623003875 965711256 547656921 451461541 165101028 403519548 989640246 374193058 518997329 761221745 897263437 821187888 543030669 611639588 304935754 742460662 125837183 318064841 816041355 928324072 355339012 655046181 528959068 616237087 521577501 11176709 700973030 278442412 412844855 274426744 23508817 810957703 180277338 398286598 937930565 311899697 939391678 17605820
Output: 1347

Example 2:

Input: 2181 373391107 154583700 440968225 540614662 32282551 359719197 313859050 347924845 456545634 344777587 263183418 295865027 567554601 423173570 675699185 4753786 889417926 507772640 27791360 791668647 936603412 923971068 854644575 625746571 807854171 590214668 826007569 731458168 558580962 868769577 7369307 206368728 192806114 387148207 305364147 487724207 622254118 777581928 766230288 321434818 822732850 85340428 581782889 807001948 175107366 700773792 495647694 691769141 547111142 543870272 277133239 28253753 792433119 707771720 879117620 687205449 157748087 828246969 712204221 574720901 434578651 600077307 869869506 249932851 343151639 186637128 75299026 794261192 27651356 730887869 4196056 224500761 675544373 642984266 745462808 125009551 523946639 12151657 555159931 503558029 60417438…
Output: 1168934

Example 3:

Input: 213 375473416 679856884 594737299 728072959 408317136 931127057 756542813 389976399 545770128 508501654 426651233 713015513 972583983 617623738 848161499 858765610 915810137 623733547 620920035 44282534 504515355 30856956 411543127 761857442 775804716 96477327 170240660 9584731 100563636 74707221 154194330 368316099 125157101 70218463 648919612 662277552 247410263 856871902 506476454 208892318 617879820 663103618 725846421 460029847 403580713 260895540 130530606 58323927 522379427 360025733 914871494 166428154 90761836 312158281 119683403 905617702 199878396 419463508 427988146 139384053 192592112 691611029 808620014 614036051 118632973 519798330 483014383 219202491 745049947 484984072 144074542 351429081 598714938 932546552 100264830 10884624 775100333 205198856 89674335 674180960 6716095…
Output: 11185

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Quinn's Brass Ledger - MEDIUM Coding Problem | CodeTikki