CT35953

Varun's Disorder Count Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the mangrove channels of Rootwater, Varun records each ledgers 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 <= 2497; 0 <= a[i],x <= 1000000000.

Example 1:

Input: 2039 735379659 748403806 380357350 220874839 712415899 450966708 140142356 870226910 238376366 239622280 658506752 308043102 949032796 25509492 980674266 341096440 887070922 458698162 370786313 738129312 882487935 306874822 435310726 509706229 796390646 917012139 749505387 310370275 742121198 577615655 331213104 660869477 93658348 770615628 290930026 497698850 777304799 385046029 459632766 839276109 930387641 359723045 613321205 236664369 225985756 200055504 784419824 415230663 91250021 708805375 252427390 371658132 141039435 615562529 653154418 48254773 273589560 456272344 50889091 39774047 437407432 466732653 483519300 85922454 268724522 689476665 524914578 452293869 465017779 169551506 264723085 67928464 20310878 275799748 315769657 872797706 925787823 439847888 735702195 466962673 4205…
Output: 1034322

Example 2:

Input: 821 635584568 537370556 847002996 240860184 988653429 823316499 673208538 979455227 321475268 501843258 552354100 552830982 218107044 651124969 44308591 823556196 699179434 86112804 563105618 671325422 478475821 879514500 833738490 414547496 822637324 272113467 324780431 161270274 409422527 125064440 256965899 235594507 624717466 467284237 789250935 422913177 628974396 762814577 63080143 219240205 567816819 864478510 602043356 234448829 505892046 614771976 613307402 250063063 488413117 849295397 775024866 764279882 743304591 179931545 98147775 418586559 655343272 851322499 553537080 387029965 695278413 226021020 906756936 208835630 922283067 352907383 264501470 337068166 870870955 485353616 85032824 568528735 398376351 996034039 168245761 616186262 854682166 299997781 8162797 794934163 887…
Output: 170508

Example 3:

Input: 689 624188768 651558046 58432062 694340090 544749769 446743583 792724080 211513611 695609359 364116960 681404721 783674742 611866448 457215913 933644865 616935786 88092002 861309344 156262335 525918149 616585064 400108050 866539961 154339105 798510897 872899107 922565360 684688765 781474884 572253441 486959695 257847190 722205332 946538923 926108728 367250249 208908191 969976487 133627969 207903598 997036976 890503881 615138828 801074277 486345088 936004255 543496410 660170066 517913509 559158235 386895704 233399085 259297473 228847422 72823850 504447164 178988620 787233434 32357087 512278802 155637334 525853635 663086563 919783267 54011435 412446875 882794743 825543526 94542493 72219424 106927353 43912061 800342569 993926701 366143417 450933069 76965360 251243034 648612361 784172510 26508…
Output: 118894

Constraints:

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

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