Comments

There is a solution for E in $$$O((n + q)\log n)$$$, using m stacks.

https://mirror.codeforces.com/contest/2206/submission/365799729

On KANCodeforces Round 1069, 5 months ago
-21

Hint: only O(k) positions are candidates that can be filled with a positive number.

My solution https://atcoder.jp/contests/abc430/submissions/70626965 notice that the set of possible positions of number i is an interval [l_i, r_i]. and you can use toposort to count the l_i and r_i l_i is easy, see the code for r_i, you can reverse the edges, and calculate "l_i" in this case, then r_i = n — "l_i" + 1. sorry for pool English (