CT59126

Chaplain and the Copper ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The harbor bell rings at the old quarter of Brasshaven; Chaplain weighs the day's ledgers 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 <= 3787; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 1611 678783 -706086 -252566 -713632 -814518 713684 -888051 585999 -879805 106331 730543 -1869 6190 856701 742431 726286 -388871 -480802 -256328 787190 -263405 -386452 -437719 273213 924072 -408098 -452856 438584 -325349 -177508 847179 -192857 379441 -984025 820109 -658539 -237944 -633820 302189 163287 -992561 472556 60441 -457403 -418960 -248285 783213 -427564 503577 258605 -330909 919519 -145681 355384 -512082 133355 -714447 -722608 -12586 92162 -670074 -920735 -940644 -433295 -88558 448721 587229 -339217 794463 498510 796670 -97253 859011 868678 878254 828243 -24225 784179 637229 318464 -491195 127758 -852700 -360797 741916 75818 48668 487294 -996332 510617 -431799 -690498 104046 710605 801231 943198 -9545 14070 -120459 739845 -898912 -516500 603496 -900433 713 649013 -779960 -117895 -46…
Output: 645018

Example 2:

Input: 865 375463 -752906 -143852 -312310 -50350 986609 305342 -542271 -900631 -98848 -251574 163339 -777716 -282785 836340 -413505 -515074 244951 -873079 51908 279536 -657303 204670 27136 -469030 -141587 -731636 251097 94497 187279 -103902 -676973 306637 502136 -251490 611183 -233995 -957355 819252 321599 684818 896977 44680 457064 970021 -329985 68815 42878 116319 -407137 345602 168575 -961223 753349 -685724 132873 502203 438534 -145540 637310 -706918 920670 536984 -164539 457646 367954 749752 -592980 -803164 -348493 756602 -322957 999916 -73659 -379588 -40695 -511377 478887 579198 -788400 845389 233168 681506 521751 -203012 757469 879917 386206 90033 889286 471830 -435672 52680 979246 838651 -389045 -641735 885932 -684118 643934 -246891 -766980 972830 -566238 -211224 240603 900219 -954338 -152…
Output: 185656

Example 3:

Input: 225 -747811 -164784 -609826 166978 523259 -867470 -727310 -996243 554931 -762825 -973262 -928668 -691195 468746 -511045 309063 -914920 729690 855989 -104758 -46691 -363654 337614 -215532 133718 314587 -321416 -266453 -735253 969294 -437681 889314 -276767 -720979 490749 64549 -900279 855958 -940399 -360096 496985 -813765 849569 -128492 -154328 978925 -326641 854369 36218 -66141 -570237 -953981 -257784 -730973 382728 525273 299469 -96091 497812 -426520 -813912 178627 578444 432549 -415863 -668604 -491508 -891582 438134 353343 -441141 177008 792408 -942910 -885269 -342148 -417637 -75098 -503362 480501 -458185 718429 -412829 805666 445 -315279 -411417 -272435 579837 394342 834656 786094 108884 104611 -195429 -22449 405965 -338481 440977 577139 919967 -603766 -719970 -224654 185137 302493 45419…
Output: 11246

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chaplain and the Copper ledgers - MEDIUM Coding Problem | CodeTikki