CT58044

Kian's Ledger of weights

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the cotton rows of Whitewick, Kian records each weights in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1469; -1000000 <= a[i],x <= 1000000000.

Example 1:

Input: 1419 797 157 1090 1305 611 890 1372 1100 668 539 1152 1064 647 1318 1124 678 857 744 299 67 509 962 127 472 1413 558 370 878 479 854 474 1385 254 821 1223 494 617 322 13 1296 517 1281 402 354 155 1277 518 1391 166 362 115 156 664 1243 1058 1182 1091 748 1340 144 16 1134 540 657 78 1186 1249 1102 822 394 179 753 799 716 649 441 34 791 1269 541 346 189 914 410 1302 307 941 1358 1266 1367 798 1384 1238 46 1360 1106 117 375 576 787 98 171 1040 886 301 287 843 510 522 718 707 1230 673 636 1109 238 193 978 23 1307 306 626 164 609 318 908 582 503 200 293 728 1403 559 1138 92 913 473 872 1170 984 492 661 405 1012 439 290 1234 1194 432 523 120 1337 133 100 1035 658 367 998 632 1320 1067 97 1071 230 989 625 1187 743 1175 1273 86 918 1150 1103 887 893 455 533 1221 416 5 555 187 271 1229 464 888 1016 …
Output: 508863

Example 2:

Input: 1114 959393424 67264834 140124322 652976833 707927361 973505412 896950767 410468498 74715568 955013900 102247342 52978207 341584313 103596683 65658631 241538303 630531464 140157439 995156863 160898654 679095403 191842738 599341888 157738812 504976154 43639013 156851685 484051137 685439329 993420982 405715725 379852096 12691364 112498882 487742807 626033614 405874544 812851173 906808703 684184800 107456959 279109438 570070924 476116298 866482879 324162960 47538761 895516909 297921784 394887043 108137410 405074950 197358982 950134923 139405713 630005422 888805707 314352340 355936408 115010519 412096891 986352887 536132627 917177664 222881530 729667825 207779222 149361630 271162069 308719952 137484054 826408449 46243428 414341809 30371961 274399728 599692355 846368929 498646016 181906865 5276…
Output: 303008

Example 3:

Input: 446 16178771 767251702 108527270 735503539 91415161 246777576 830082237 910142967 744893972 397782242 514322140 501964858 397597469 884982300 45239362 207258559 544565625 402581200 465197693 879795229 612925989 481191603 166737621 212264120 301705846 751750498 265555159 532800439 145339801 767572447 405343448 134443478 53790543 523050030 706776052 112732973 256778939 832016890 290919552 930755969 642110202 917766462 260382671 581618245 694543572 240112761 443334143 356743398 995121152 423784310 575047291 778422370 151492669 549724010 357474866 921095726 525936245 31396172 656843141 346702281 22423562 394036626 659844000 631570736 330085932 736163067 839288238 732611590 999316868 350364293 221251305 561976415 269605824 246546991 178978074 97961951 327421356 443365219 474237077 32269960 7140…
Output: 47716

Constraints:

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

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