CT59677

Bhanu Counts the shelves

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The harbor bell rings at the ribbon falls of Cascade Vale; Bhanu weighs the day's shelves 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 <= 2845; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 782 316 451 348 741 210 321 435 232 577 686 220 476 392 447 756 414 147 677 365 225 582 617 391 700 193 510 346 341 576 444 734 238 304 575 692 455 770 32 459 91 506 287 158 139 72 427 586 484 742 698 73 9 683 508 171 759 636 86 534 83 268 501 95 192 284 585 486 300 529 589 609 563 429 29 674 454 116 12 517 622 288 552 311 352 631 271 103 403 418 258 545 749 776 97 278 393 713 466 237 169 203 781 635 559 246 611 281 574 720 703 58 750 197 603 118 196 105 5 584 549 569 481 317 443 522 133 583 528 302 39 223 728 652 705 474 249 592 710 554 318 587 338 128 330 292 283 496 762 59 15 344 504 513 253 18 33 28 679 428 125 290 313 404 370 101 518 170 448 446 297 663 649 361 557 187 254 543 57 778 213 601 209 394 748 23 485 753 80 31 104 205 241 37 767 413 262 211 771 212 265 439 136 490 201 639 39…
Output: 155440

Example 2:

Input: 2736 229738 -395089 148278 -897133 -512724 -410551 -802797 -148430 637379 513946 -936556 512680 449539 301946 -7222 408829 837147 676778 589708 86961 -37942 69986 78314 -651810 421309 -393084 785566 693173 -690748 259602 92599 465673 -249795 -905008 -897810 -807753 -922927 -531274 -595145 701362 297121 -252463 -355831 941670 123532 976879 909083 -431094 167061 -552272 55175 153525 590491 -796932 -608029 -693206 516557 -995064 -499235 36266 271067 487937 66866 122382 -544068 -975639 691991 -73834 -333040 -678016 -285245 90915 -631337 -220505 -840207 -464947 273843 897056 611072 312373 -280462 93928 -33085 -578893 -589986 -37570 -861546 711335 -223234 -893796 -340169 -453474 -445450 994138 814379 533529 -3365 -475136 563562 187564 204671 7431 990866 166934 787812 8562 890458 -610483 -487201 …
Output: 1864247

Example 3:

Input: 2553 203349 408604 -450803 52378 -721544 -34534 451502 -252139 408902 -342184 57657 643108 480488 -664573 -746985 168669 924113 -2529 -797900 849263 132356 -843600 460625 919475 -841450 166333 -374302 616391 -624321 759045 -931231 341832 914729 -354407 -325242 800881 144178 -534414 -745695 618436 -556187 -172162 -865496 -442272 898199 688420 -922013 559754 -74773 -925086 560164 417273 259207 324382 117674 247208 -679873 661605 553492 606829 597534 -840892 310093 -741226 -676344 -189223 -914269 995260 117517 -233161 -199005 235841 326052 754836 -77611 394834 -635193 172011 -217194 -143616 -568675 225503 -187449 522282 289178 341564 -190970 -410956 710969 512737 -165772 937392 659244 955296 72796 20896 -44407 788233 713222 -572054 -339502 182469 -176026 -327448 428938 493092 -449189 -866973 …
Output: 1654578

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Bhanu Counts the shelves - MEDIUM Coding Problem | CodeTikki