CT39400

Whispering ledgers Disorder Count

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the tannery row of Leatherwick with crates of ledgers, and Morgana the measurer must account for every last one. 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 <= 1613; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 305 -252850 165360 735007 -969590 -58001 -206708 -510300 286739 -2091 -266539 85938 -494991 14201 -703257 104846 762624 -204311 967003 -166116 415090 848610 -342317 -794360 -109911 -164095 -721618 -505786 309360 -422603 -341146 396707 -268054 -762104 199837 -280196 290815 264059 -837756 -31086 -11599 -892283 202711 297156 -386196 826822 -803157 532455 -477298 -231047 -185412 62287 838426 -101827 -214593 -507454 70230 802390 892900 -121872 382986 -222543 -719458 629466 -781753 617597 -664456 180731 562024 149769 502455 -922847 945133 -24141 78718 -873226 252735 -553569 821807 917634 345966 706925 141547 319488 -484351 753057 970722 438033 -577055 -722709 817462 -57977 -87941 594899 -182420 95844 668260 -787605 706602 -724957 -667792 379198 940427 -424055 723626 209142 -318490 -188393 -55217…
Output: 23056

Example 2:

Input: 1474 -572658 -707535 -139466 -447208 -550150 -649501 -288018 534128 -775639 893463 -994315 931345 -596144 -319937 -210858 -755496 -292709 -283283 812870 -613198 -907510 342129 960404 998783 769849 -486781 -687721 784706 259003 994026 -480055 -760724 861327 915734 -463580 -456829 925869 -993715 443969 794560 -71587 -420160 344777 -876714 425530 581461 -385433 55404 -65408 -662930 -689788 159109 257875 -207254 -25071 -357792 -584501 -605504 100051 772496 -588858 -99300 703383 -782991 -923446 844987 -66317 315081 162509 659562 831561 -707151 11942 927256 694176 517778 -512704 899320 -84402 -296391 682970 -101890 114295 -290431 -498728 -571192 -517640 -319371 -18006 694984 -77448 362757 282904 -655638 874449 -317847 -465947 74626 102575 -939848 -971213 -898867 55299 -571895 234917 -44115 -2049…
Output: 535716

Example 3:

Input: 1206 640 552 1006 921 437 135 865 895 789 366 764 788 678 455 65 531 100 218 1000 853 1191 739 251 103 743 98 833 317 23 1067 356 551 582 892 557 392 1183 579 839 716 502 445 1197 1112 848 132 970 633 630 1001 34 1205 953 291 751 1010 871 1014 465 1185 202 15 76 541 746 778 832 195 150 298 42 899 740 21 803 377 207 801 115 153 830 935 731 346 797 628 433 67 646 309 1097 499 311 444 48 55 987 796 1131 548 77 722 85 779 1015 1128 883 798 1012 968 82 93 536 644 611 17 318 152 368 1040 696 209 286 391 409 323 870 214 281 1046 1073 1194 156 632 420 313 386 728 1085 786 836 649 863 1065 122 1193 1062 977 1177 1134 992 978 478 763 942 1108 783 535 495 709 237 822 57 1184 1143 436 1076 679 1179 795 595 273 463 812 464 700 876 397 627 609 1164 941 659 698 1034 87 682 666 1024 559 517 266 1025 636 6…
Output: 359413

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Whispering ledgers Disorder Count - MEDIUM Coding Problem | CodeTikki