CT57585

Mason's Ledger of vials

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the monsoon port of Rainhaven, someone must map a faster supply route. This year the task falls to Mason, armed only with the vials register. 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 <= 1356; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 689 38 77 31 567 253 19 592 419 624 12 175 243 412 636 308 309 487 165 162 587 10 327 482 13 116 319 284 485 104 249 583 134 314 410 617 454 1 317 393 474 440 242 277 678 61 137 520 306 496 584 480 388 85 75 27 350 193 99 195 445 339 590 385 655 50 4 271 432 311 491 303 681 492 296 524 413 427 312 91 593 46 139 680 218 24 291 382 481 83 431 500 386 672 640 283 76 666 58 151 402 128 92 577 555 157 265 684 251 244 161 177 425 459 609 462 156 424 206 637 611 236 653 401 74 464 570 523 376 562 22 250 671 167 153 630 257 346 494 663 115 475 677 225 107 302 248 495 35 632 45 15 652 62 366 23 194 489 9 238 28 522 403 374 651 200 213 639 140 188 634 105 573 269 623 281 82 246 398 600 354 608 510 604 407 416 255 158 448 544 529 394 553 443 456 455 688 558 21 414 147 447 122 329 273 252 357 405 353 …
Output: 121032

Example 2:

Input: 1045 -807537 595077 57482 469867 572131 750461 450278 -148393 441791 -15022 -115944 -147942 128502 -782286 712039 66557 -389697 -951529 459488 600005 -538052 -278233 218137 -923212 -637141 -758257 544652 786408 554858 -925381 311870 288547 -317762 285194 508735 859305 909469 -141505 990025 -970882 497005 -789769 303069 834929 -210894 -784401 -58903 619005 86859 -748273 598238 835394 -428974 -131267 -203281 -109131 -501514 -945288 604747 556919 934813 197715 -284404 57234 901895 -878238 444020 -159504 -37867 -298829 439224 -80257 56015 -325115 -322338 783949 836663 608473 -898693 -695592 -930163 -860211 -227412 -538415 -478901 405090 843973 501358 -70588 -473802 28246 -912965 -152069 719832 792935 -416737 -799706 435650 967492 158275 48592 -323171 -902238 -925969 -752761 -663772 155678 -212…
Output: 273784

Example 3:

Input: 720 -144764 -33187 -592520 -602315 45599 841894 -495838 -904731 383980 256048 283594 507299 931120 -129345 -16848 958570 -61599 777011 377681 91950 707277 708266 -225353 -714928 567783 -881634 527382 -248666 -351170 -668859 -712386 129535 477537 -481344 -173344 -320736 -355180 -967528 -864532 464323 428669 185953 -902268 109320 721337 93038 80870 14771 331947 782455 -414366 -162075 424511 865934 793318 541251 302901 655209 867448 579154 -445321 847954 -958108 -393495 982378 -185604 796704 985662 711722 -501194 -625365 -714106 -535197 -21147 858594 -760361 856337 196949 357972 729407 -363747 67724 81736 119270 337529 229554 461866 436525 -33880 768509 -701036 526751 643684 -330843 -627840 -507054 -879712 -840118 561878 -774316 -968247 -350062 185881 -515576 665635 -585712 432888 292514 -979…
Output: 133202

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Mason's Ledger of vials - MEDIUM Coding Problem | CodeTikki