CT62474

Hema's Garnet Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Hema runs the chandlery at the fjord village of Deepwater. Today the books show a list of registers, and the numbers must be worked out before sundown. 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 <= 3218; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 1354 398032 91706 -868942 -190261 904685 -179152 19985 454561 -943439 -176323 755946 226317 129681 -228703 -726823 637331 -460700 -66998 66332 -387833 194950 54875 522119 318912 -123791 383116 -392934 -471008 -703623 269581 835869 365496 75915 -510289 156881 -876878 427047 944764 -874899 -276014 -214641 -287342 -845657 -805092 -103615 -493952 761731 -841793 175860 -256880 433015 -287853 -278892 177229 -912456 991855 567379 963271 -243191 315642 -689224 894253 666777 -116806 774302 -843577 446620 -155872 397370 -613319 519817 458566 376075 -311852 509907 283396 -141201 529584 123458 -210607 674083 516569 -725331 -97795 -703517 320257 -775127 -7787 -669700 -907445 699639 -788649 -296127 509177 939520 99251 -402085 58252 -68519 -792950 -433121 972124 645528 -883692 -86149 -780147 797032 -4924…
Output: 444033

Example 2:

Input: 2055 2007 1285 1589 309 6 164 453 644 1724 1612 1167 867 1363 986 900 1338 415 1257 376 1995 296 1117 1980 628 1692 919 639 247 118 250 1659 1133 1578 412 1429 1770 1079 1356 2006 2034 32 79 1106 863 124 406 2032 1957 244 1994 1227 1993 371 1326 509 992 1012 1108 979 317 1870 1815 938 372 14 1843 1799 1817 1748 2033 1930 1934 1001 421 2001 884 495 1132 285 1897 683 1976 667 1237 1244 1693 830 530 186 35 781 1840 2023 10 1867 595 429 807 1126 238 1911 1836 1016 1473 1712 425 765 571 160 1353 880 88 888 224 637 2029 1391 879 646 228 770 755 961 1961 144 1533 119 1466 1011 1656 1506 1258 836 1023 928 200 252 657 806 656 409 399 1215 1690 1508 1321 993 152 1146 265 796 1138 822 133 1402 959 1387 1328 47 1594 1390 417 1067 1298 1557 48 1045 1839 243 271 269 1979 1279 1921 1479 1523 955 753 893 …
Output: 1042108

Example 3:

Input: 1748 388246 567365 -486246 -990730 -997698 521308 -466684 675874 614520 437789 -329624 -996724 -287671 -689368 983192 -806689 -898738 -205461 936636 -389052 -406305 802276 -921022 862196 -135421 -147040 822398 412296 815341 -66975 -172951 441222 532088 113781 -647963 640812 -357672 -415281 -630268 -291710 -790784 660842 254741 -749470 49111 -332190 -391983 -952493 685870 521419 -353318 256283 555999 999508 -851291 -143714 96235 688496 836636 237875 281808 369626 909451 -617096 -829707 -114368 265558 681829 -243915 -316621 691151 597965 871267 -708726 288515 -410945 560019 433837 -222917 -764365 924189 -323137 895524 262174 -808773 -393597 490030 952030 17569 -879896 -20098 -576327 408482 -545148 -765618 349694 -18676 287294 390145 -776737 -443076 737520 104330 -781663 -151470 552060 898914…
Output: 754415

Constraints:

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

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