## Editorial for DMOPC '17 Contest 5 P4 - Intersecting Arcs

**only**when stuck, and

**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.

**Submitting an official solution before solving the problem yourself is a bannable offence.**

Author:

There is no intended solution for the first subtask.

For the second subtask, let be the number of ways to draw the arcs in the first dots so that the number of open arcs (only the left endpoint has been drawn so far) is and there have been exactly intersections where intersections between a completed arc and an open arc are counted as well. For each there are three choices for the dot. The first case is not putting any endpoint on this dot. This contributes ways. The second case is putting a left endpoint on this dot, which increases the number of open arcs by one and doesn't change the number of intersections. This contributes ways. The final case is putting a right endpoint on this dot. This decreases the number of open arcs by one. Note that there are possible left endpoints which this right endpoint can connect to, and depending on which endpoint is chosen, can increase the number of intersections by . So this case contributes . The final answer is .

**Time Complexity:**

For the final subtask, we optimize the solution for the second subtask. Note that each row only depends on so the dp table can be compressed to . Also, for the third case where the dot is used as a left endpoint, we can optimize this by computing the prefix sum of in and using this to handle the third case in instead of as previously done. The prefix sums only need to be computed for each and , so that gives .

**Time Complexity:**

## Comments

If the first 10 points have three intersections formed by arcs (1, 7), (4, 8), and (6,10), and there are three open arcs at points 2, 3, and 9, this pattern should contribute to dp[10][3][3].

When

amoves to the 11th point, one of the states we need to calculate is dp[11][2][3]. According to the editorial, the above example should contribute to dp[11][2][3] if the 11th point is an end point of an arc. However, in this case no matter which open arc is connected to the 11th point, an additional intersection is formed which transits to dp[11][2][4]. I do not see how the example can transit to dp[11][2][3].Can anybody explain where I misinterpreted the editorial?

In the editorial's solution (which is the only one I'm aware exists), the intersections are counted when the left arc in the intersection is completed and only the left endpoint of the right arc has been chosen. So the intersection you are asking about has already been counted earlier.

Edit: I've updated the editorial - the previous definition of what was being stored by dp was incorrect.