CT39421

The Disorder Count Beneath Marigold Row

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the saffron fields of Marigold Row, Kabir records each weights 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 <= 2284; 0 <= a[i],x <= 1000000000.

Example 1:

Input: 485 422 281 194 75 174 263 448 304 208 189 9 438 409 262 52 165 115 101 383 185 350 446 238 155 330 204 368 419 276 346 209 269 355 19 352 178 342 102 311 297 78 49 245 454 67 110 410 217 365 411 77 161 229 35 401 341 279 170 348 253 271 134 131 193 337 39 457 373 249 426 119 16 105 240 436 384 264 275 23 396 433 351 65 463 254 66 480 441 142 176 361 91 199 195 220 292 267 386 449 312 203 90 273 68 95 184 230 395 234 143 61 257 484 120 18 377 288 180 150 241 181 54 274 389 259 116 211 106 452 124 213 408 62 145 252 166 223 74 462 328 416 403 218 151 325 43 167 469 323 214 183 5 357 70 306 157 405 442 125 291 443 398 447 343 8 387 243 354 7 206 158 244 25 364 369 144 460 10 287 130 345 147 175 84 132 73 302 326 366 46 375 202 397 423 141 478 300 200 444 212 256 472 159 11 333 82 467 168 103…
Output: 60207

Example 2:

Input: 1724 375785487 793827792 915069196 235380743 344482723 751316307 925493205 658677700 314956614 276237172 255399453 8456386 612547423 814689028 877899440 542618152 263958210 435037109 971168307 685027827 718858621 473688240 160831718 848300674 992620127 769154892 774274043 864825583 3599801 278839988 582038418 706804381 846427744 843264624 428435422 711515084 597326259 932314173 337177403 551174576 658048216 528766992 159289761 494030352 731463575 324658304 48282227 157653464 924526538 610798900 990603514 318139416 156925310 43029395 223457970 942731151 649706587 311185407 483553543 783558428 995200389 882864215 416957274 2023934 255226097 811882002 488832905 428997942 439964271 767970399 410129194 399431212 507065431 736168578 728247175 664475431 379734450 278983269 404104954 817985380 954…
Output: 751444

Example 3:

Input: 324 268636737 306628039 660156068 488517803 415176150 728914894 579973480 188317868 130357044 998452333 438900102 815005864 181728784 598615466 58279673 158161621 903436765 851347581 595886906 646419838 412627585 540634744 497087346 487408454 469486032 549270295 721730394 255587531 42674237 542025983 177571746 987155743 627042620 586127802 127213626 786253153 606540932 186738205 227890529 920913991 209192968 954723430 168727555 174959154 381868635 759746734 708936079 186556071 597940051 702918037 750362832 964065174 762755750 972144545 237110397 953950374 235405308 96311352 830490042 844353696 403943649 427438863 917739393 59003593 151629292 712850689 575606960 108668097 64901350 753830146 586245873 807645700 330233143 578122183 541553736 359748804 38133831 604746078 699303230 834257312 31…
Output: 26409

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Disorder Count Beneath Marigold Row - MEDIUM Coding Problem | CodeTikki