CT38710

Sage's Ledger of crates

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the shale slopes of Greystone; Sage weighs the day's crates manifests and starts the calculations. 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 <= 1775; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 1755 -49067 -936446 -686933 -663615 80737 -896641 192463 -964404 623900 872540 74127 765550 -149993 966503 -89800 -438971 133040 312319 877448 -624422 201204 973418 451545 -284660 113337 -559261 -417788 -934762 296515 -207952 -137013 813130 -421368 662798 782729 949620 10196 912005 -704824 543120 -100448 -857325 58408 -55473 60647 -465360 293046 496916 224651 -146235 -747686 -139584 -380357 -964196 753483 -869177 -502635 381660 -51954 713756 124006 131714 -350165 -74357 -550172 -34521 -96851 -722529 480783 406138 217838 -510556 157761 810197 -393692 983334 604729 118079 397966 666384 -565058 317239 -338889 -836090 160241 601909 80191 704222 -636480 -732795 847406 342888 169574 -208863 -1359 544052 -274668 -508172 336955 526627 988767 537303 -755074 -647098 -584248 -799621 148774 514518 -85…
Output: 769231

Example 2:

Input: 1098 901 1053 523 662 427 1015 536 928 178 30 1031 520 702 687 889 327 605 478 300 1026 166 884 189 445 266 256 783 23 140 35 1088 883 767 708 1061 93 99 999 666 467 446 69 813 150 899 652 252 318 142 187 592 661 414 382 633 157 945 570 863 677 521 870 705 615 550 778 63 243 1014 1047 576 131 755 366 542 1094 1044 753 236 906 218 134 388 994 554 741 865 438 40 507 1017 809 387 403 751 858 466 665 159 622 385 660 34 798 966 434 733 775 469 185 136 700 435 958 38 537 221 612 806 61 876 670 96 352 433 114 364 659 903 6 213 171 996 973 574 646 548 1054 832 357 208 518 625 977 954 710 707 43 254 541 482 71 390 135 341 424 220 602 1073 13 601 879 237 77 130 1050 118 52 265 231 214 349 1076 735 381 828 853 278 912 918 590 560 417 941 260 460 816 1070 143 476 109 501 723 89 711 921 439 80 967 74 4…
Output: 289217

Example 3:

Input: 1298 -950576 -286520 226026 -751532 -340095 301199 662466 357200 -599981 -13829 701447 448112 -461399 -871784 -342407 591928 -559711 -23461 -101889 -585528 238652 -41730 -397341 -958157 -843913 -769264 -53854 -555144 812386 -847175 -215857 -348678 498175 525324 -558490 -231503 173641 93718 -83755 -284263 -665580 246066 -672995 -633836 -209161 -97852 -996428 517212 -523029 343526 -755743 -588811 279660 829753 -841194 -13973 938284 651920 239131 -535363 878929 741946 434051 -34132 331780 -156457 598147 -281080 -589372 -800957 -354253 726780 -844105 -595223 -607750 -543317 406173 843657 202946 460293 -271369 -786309 944017 834300 202257 919402 -418550 253595 58643 284790 1167 76062 -821928 -599498 336020 662328 -500064 -190525 891150 -739251 -101275 504244 146203 -592911 557014 841287 -788970…
Output: 410683

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sage's Ledger of crates - MEDIUM Coding Problem | CodeTikki