CT36747

Omkar's Sterling crates

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the floating docks of Skyharbor, someone must secure the caravan contract. This year the task falls to Omkar, armed only with the crates register. 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 <= 3186; 0 <= a[i],x <= 1000000000.

Example 1:

Input: 1029 62757524 328590559 567802911 233841757 694502809 389945677 834091214 710672332 438762854 891893819 504902849 792130995 454455681 741171214 284014593 914239551 581216105 36544967 416372841 942876864 443705634 207795589 214177473 923739864 626097347 446781020 125742707 256923287 591236097 787087924 252134701 531300595 189179299 724811953 169452447 97001487 979251602 943414264 480119255 420994973 954609064 51291747 684192086 185711225 843562308 213363045 649978652 578538516 152147479 981902455 179681015 257045669 243331154 94664625 450116055 189993250 672651348 205908237 178768555 470283640 685435882 717080175 210193941 746655929 532427960 56245561 941574941 687923395 280803522 686128511 835996176 529461755 107232474 464898862 892134765 910840792 993316824 294498936 907128859 895438435 5…
Output: 267592

Example 2:

Input: 3064 1909 1174 2830 1496 1335 488 3013 1145 1114 265 1552 2123 808 1391 2993 1799 2916 786 1961 2769 1511 2576 1549 2687 2793 2969 1045 454 2234 2237 2198 1663 272 3025 1925 2668 1372 497 2934 1952 937 2270 396 1270 1894 2347 2314 2652 350 2724 979 603 2116 1635 1887 2678 674 2826 1416 1876 2266 2208 230 2623 1091 240 2940 557 36 817 530 1792 1918 353 1920 1771 2149 2058 269 1807 1603 1770 1881 2855 2661 1637 2704 1803 348 2186 323 3010 2783 763 1680 2523 955 746 1430 435 2893 2942 1640 1220 1103 665 2603 1233 1530 2146 1152 734 2968 542 449 1612 322 2728 2145 2510 1829 782 1159 2448 1364 2937 1093 2690 338 1286 1775 2891 1320 2791 702 1779 1652 2290 470 236 1709 429 1410 835 2282 524 753 1627 2890 1515 666 2183 2431 2271 1723 1561 1748 2755 2028 1587 2020 2249 1572 133 729 195 822 643 228…
Output: 2345012

Example 3:

Input: 1901 631010153 633927326 747537069 433792540 379784133 966611351 992954173 2848327 883891289 733428474 931205440 468747225 409754950 73989961 768131851 208245527 985270931 945638628 738012522 387003496 842575280 11716360 494081772 205427230 993187443 196029752 84578520 442904093 427802485 370733366 916161358 862013967 336922024 690594498 348590281 972043606 357478307 63701846 391518158 162355661 28380393 146558172 144713247 996023630 528141241 753558622 281909992 732797001 86431271 957533068 178540636 312061374 771452230 740159736 609973236 201859127 694969546 720795325 70355779 572156242 436282991 401847145 44562013 464866639 987547029 996210727 354996523 621034711 597574251 260993923 850437543 694701397 956903179 580908557 890166549 74428875 945711845 419174318 436614933 270368015 201325…
Output: 896176

Constraints:

1 <= n <= 3186; 0 <= a[i],x <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Omkar's Sterling crates - MEDIUM Coding Problem | CodeTikki