ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1523. K-inversions

It took pretty long time
Posted by Mahilewets 17 Jul 2017 16:52
It was hard to understand how to calculate the answer.

It is relatively easy to invent a correct solution when you know the expected time complexity.

Solve the task online,  read elements one by one.
So,  you have dp[i][j] = count of different j-inversions ending at element number j.

dp[i] [j] =sum (dp[p] [j-1]) for all p>i.

The answer is sum(dp[i] [k])  for all i=0...n-1.

As mentioned below,  an array of Fenwick trees is your friend.