CT62291

Vera's Moonlit Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the cotton rows of Whitewick, Vera the cartographer keeps careful count of the ledgers. Plan the festival budget, every figure matters. 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 <= 2389; 0 <= a[i],x <= 1000000.

Example 1:

Input: 1888 776176 96564 540043 325553 925824 748857 682610 733925 365096 134697 720192 75161 156272 313049 701474 35634 485035 463486 407436 106024 473314 640879 414476 761802 367755 992943 315341 915926 129267 156529 300315 927003 81855 276955 132565 418750 66597 734006 610828 573952 340303 595826 592676 718486 923855 728001 474364 340288 104466 901295 304520 866226 62837 831344 669103 668164 208522 425536 323567 623211 13335 833960 530373 915582 784321 388070 160837 844108 114960 76401 946831 725560 475616 43989 949158 781136 975350 976775 306907 762721 352505 166898 472316 164997 328072 906906 913076 654629 395369 345852 379468 194687 54758 705760 102288 673735 811749 405013 893874 748483 99452 258350 900830 803693 522329 703683 494390 127611 982717 777460 735972 392535 80525 916989 736475 23…
Output: 885477

Example 2:

Input: 1344 474599 626217 836828 733731 53446 800186 998071 821236 382618 47549 409406 196070 385389 375646 227212 602137 773600 649523 532812 995168 375349 59872 45041 518220 415563 720428 413942 221930 569132 855481 643734 374639 919531 2222 581885 877164 499730 283585 253721 337038 101078 723954 152239 232606 697990 711615 278816 289239 328213 369198 443668 949137 957597 662757 198684 416698 702530 828995 376540 116784 683761 873833 205681 49704 590040 414079 286625 441216 473440 392123 842082 799914 253434 954921 833762 420378 783076 15996 860677 13563 665713 183414 75322 932540 688496 836753 329963 272507 907815 197530 170561 206007 702153 136209 504214 720289 179756 35320 61239 317496 618828 772082 759923 217784 926765 992414 532218 504557 186362 756795 883747 903982 617867 509270 152731 28…
Output: 456216

Example 3:

Input: 1214 804308 617977 636822 75495 242582 134491 285672 249998 964907 501218 307176 340869 448131 475486 994782 889734 131374 565531 167971 361875 280201 506011 356908 508024 794908 732978 29614 86709 738968 825525 989321 925537 831600 32148 248981 331801 3387 538929 529402 622131 975988 691264 725712 947360 18608 604470 697870 901911 825861 560924 723888 122913 392913 525476 293037 683414 428098 677420 247909 407417 31092 781154 713405 258640 850808 836764 697782 490120 624845 397002 323312 22137 953629 409862 218384 212860 322732 748675 670951 223353 250212 620971 673410 150588 559055 151739 455570 150049 3135 899075 936986 655892 472014 105893 592750 988836 860854 941079 971255 683511 776530 27527 301358 388947 897612 607470 588310 300295 629114 738438 527567 207309 460268 350136 253567 47…
Output: 371916

Constraints:

1 <= n <= 2389; 0 <= a[i],x <= 1000000.

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