CT52729

Bhavi's registers Disorder Count

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the archive halls of Scrollkeep, Bhavi studies rows of registers entries. One clean number will settle the guild's oldest argument. 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 <= 1977; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 1688 -345523 -631476 -717058 960165 182722 -533093 -100836 292882 -701111 750986 162104 769330 -575885 -362783 540276 864538 252545 -443247 188932 -802045 909291 867776 -705131 449367 -40478 -786860 -353596 656657 -594445 626466 854282 172667 746659 130103 -961501 -228319 872057 -865970 925688 912342 -468403 -230799 -847362 233273 515143 -233422 -145970 659315 242472 277408 -454674 947463 705589 319416 113426 34738 -217294 781007 148949 -401502 14288 920279 204345 -656571 -729821 -257069 -905214 -316657 347664 591401 65952 -628629 -10492 743839 -671804 -518008 244141 -630470 -240530 -728144 583480 -919143 -449279 -457384 611736 -991883 43335 707012 -184319 -502196 -738605 -410029 516817 -948343 541651 422850 835463 -518906 205649 -649289 458936 11589 242291 -390025 243316 87087 -520152 808…
Output: 699312

Example 2:

Input: 954 152764 -912441 -990181 965527 -677376 936435 -312714 361346 -248028 382500 -389131 222249 365435 -217389 -190090 -47595 396919 -455252 208736 145879 -215806 -865944 862597 -382031 -189287 -795616 498149 181967 970487 352590 -692947 -514930 -145785 -447286 -338853 167605 -891336 -283324 420729 -120229 176238 80194 -320829 -533791 25696 872158 739051 -433574 -592835 -152380 752515 974441 -478983 165824 943422 -308890 913125 -518253 -733140 918765 -701078 96138 -877830 -777348 -584514 -274440 996822 -539747 -5910 679347 965499 101347 -37244 62257 -231056 636027 150134 -896552 901827 709338 811184 259976 -808089 -457936 -68360 -350403 -947085 -393557 -949400 -962681 -695431 -817155 778466 -227886 454979 -455228 -159813 -299083 -510645 -222663 -202763 -860793 -998360 461264 745684 505460 -6…
Output: 226412

Example 3:

Input: 1734 676265 720832 -607014 -1827 -69226 318817 849007 823735 443902 137673 21662 -252910 -135478 523603 544002 565545 471595 -8472 -466281 -160760 48346 -290684 732319 485470 -355925 333811 153855 446612 437056 66351 199735 218864 -211250 -896990 971717 893816 -375630 78945 411335 -548419 -769123 244627 189458 847177 861970 -621645 469629 175494 -175095 -332414 -613383 517840 -9487 -938184 737870 -782994 -882467 -176899 -421572 657511 -315538 35036 -796363 -819526 -917194 -537104 -327501 883429 80074 -625453 228236 898382 -456584 -631841 -286879 195458 -293842 487909 -548576 364304 -671868 30664 372399 375244 -506373 148567 431440 425841 626104 -431034 -406292 483183 871053 496226 -751296 -383190 -939863 -214196 9685 -832349 -86459 -513371 -634225 -764005 340645 826209 -320702 -335207 -361…
Output: 746654

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Bhavi's registers Disorder Count - MEDIUM Coding Problem | CodeTikki