CT63750

Vani Counts the ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the opal reefs of Shimmerdeep as Vani unrolls the day's manifest of ledgers. The tally will decide the next shipment. 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 <= 2080; -1000000 <= a[i],x <= 1000000000.

Example 1:

Input: 555 207 553 523 394 494 407 257 441 256 466 345 338 80 249 266 243 144 124 484 47 318 157 290 399 176 320 477 216 1 274 376 225 23 61 228 91 115 415 460 192 104 369 253 540 534 356 276 285 244 511 331 134 121 459 458 397 355 209 542 132 152 342 42 204 67 502 411 528 371 84 352 303 111 545 189 141 463 251 340 443 327 433 133 267 422 490 71 311 117 405 541 28 89 128 48 379 7 455 20 527 127 172 75 430 457 161 301 308 158 323 53 76 83 109 230 123 453 473 159 233 442 198 179 531 409 245 384 153 297 551 380 9 358 293 73 363 454 309 44 348 330 37 522 19 464 32 183 24 513 218 50 100 271 221 45 125 429 191 383 400 119 150 219 149 421 265 238 436 322 74 403 481 105 240 315 29 440 549 114 211 21 110 367 3 229 512 12 361 136 451 113 395 349 344 0 273 434 40 382 206 15 35 22 304 310 480 354 203 122 374…
Output: 75924

Example 2:

Input: 1092 775 369 673 926 712 437 198 867 361 230 71 263 326 456 55 217 843 601 400 681 66 386 697 319 953 524 74 75 878 718 259 631 777 941 1035 257 709 748 49 742 373 982 57 917 147 1066 1003 41 307 919 264 115 352 14 546 170 707 43 654 827 646 451 719 224 253 802 984 489 160 380 899 889 1082 723 134 1087 417 798 517 937 414 625 829 1062 7 848 61 243 993 1047 346 731 671 275 868 227 896 949 797 817 453 1023 270 950 711 648 474 931 756 883 514 481 382 388 273 554 622 745 585 515 431 1056 397 215 643 806 629 1075 741 317 770 800 206 350 641 948 611 1081 588 547 924 282 272 649 148 1017 280 1072 442 27 1064 1065 260 485 304 1059 251 169 1085 930 88 670 963 344 455 502 669 277 174 130 172 121 897 776 271 717 351 368 405 120 813 250 1048 902 594 728 830 1000 1005 194 653 1071 330 974 971 331 854 9…
Output: 299570

Example 3:

Input: 455 924460046 640872431 684153550 472675151 855708081 97051803 21571655 475479205 630422268 633724928 704390080 719666860 52198925 530365777 318821672 588679222 136478145 102017629 296522906 415179577 278474367 950362385 568730218 696496439 268487384 198402605 605138649 711173308 942417346 206635505 148685920 152377883 221183053 22874119 269473995 996172706 523436309 656319456 847835380 792540655 746833907 23157674 224502040 282054976 344253355 22099312 62079256 271093065 218089123 151981315 88275827 804549554 458094723 679756897 392794651 94385116 23095062 389387271 640694247 739031118 139522623 667573525 78110944 675260061 776959915 618476776 817131314 650658081 559861931 983782487 19000553 146292172 551244745 451192409 103411157 813750603 185426266 525084532 558693610 852532084 54530150…
Output: 49787

Constraints:

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

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