Simulate repeated insertions into an infinite balloon line, then report the colors at positions l to r-1 after all instructions.
Hard8TreeDFSRecursionImplementationNo attempts yetTime limit7sMemory limit512 MBDarcy manages a balloon warehouse with an unlimited supply of balloons. At the start of the day the warehouse holds one infinitely long line of white balloons. Every colour is written as an integer and 0 means white, so the line begins as 0 0 0 ....
A balloon is identified by its position in the line, counted from the front of the line starting at 0.
During the day Darcy receives n deliveries. The i-th delivery brings an unlimited number of balloons of colour y together with the instruction (x,y). If the line holds at least one balloon of colour x, Darcy inserts exactly one balloon of colour y immediately after every balloon of colour x that is in the line at that moment. If the line holds no balloon of colour x, he sends the delivery back and the line stays as it is.
After the last delivery the supplier asks one question: which colours sit at the positions from l (inclusive) to r (exclusive)? Answer that question.
Take a day with the four deliveries (0,1), (1,3), (0,1), (1,2), where 1 is blue, 2 is red and 3 is green. The line changes like this.
start 0 0 0 0 0 0 ...
after (0, 1) 0 1 0 1 0 1 ...
after (1, 3) 0 1 3 0 1 3 ...
after (0, 1) 0 1 1 3 0 1 1 3 ...
after (1, 2) 0 1 2 1 2 3 0 1 2 1 2 3 ...

The first line contains three integers n, l and r. n is the number of deliveries (1≤n≤200000), and l and r mark the range of positions to report (0≤l<r≤106, r−l≤100000).
Each of the next n lines contains two distinct integers x and y (0≤x<200000, 0≤y<200000), the instruction of one delivery. The deliveries are given in the order they arrive.
Print the colours of the balloons at the positions from l (inclusive) to r (exclusive). Print all r−l numbers on one line, in order, separated by single spaces.