I admit that AGC061C is too hard for me, and I don't even understand its official editorial. Today I see a Luogu blog with a very clear idea on this problem. I learn a lot from it, and I would like to share it to you. The writer of this blog is possibly Little09, but I am not quite sure.
Part1: Problem Statement and Constraints
There are $$$N$$$ customers named $$$1$$$, ..., $$$N$$$ visiting a shop. Customer $$$i$$$ arrives at time $$$A_i$$$ and leaves at time $$$B_i$$$ The queue order is first in first out, so $$$A_i$$$ and $$$B_i$$$ are both increasing. Additionally, all $$$A_i$$$ and $$$B_i$$$ are pairwise distinct.
At the entrance, there's a list of visitors to put their names in. Each customer will write down their name next in the list exactly once, either when they arrive or when they leave. How many different orders of names can there be in the end? Find the count modulo $$$998244353$$$.
Constraints: $$$\cdot 1 \leq N \leq 500000$$$