Trails
Time limit1sMemory limit128 MB
For each axis-aligned unit-height tape, count the connected pieces of the bytecurve of order n that lie inside the rectangle.
- Level
Hard8 of 10
- Topics
- Divide and conquer, Recursion, Math, Geometry
- Solved
- No attempts yet
Problem
Byteasar is still playing with his plotter and printing bytecurves. (Recall that a bytecurve of order consists of segments, each of length . The first segment connects the points and , and between any two consecutive segments the pen turns by : the -th turn (for ) is to the right if and only if for some non-negative integer and odd .)
Byteasar has noticed that he can draw beautiful trails with his plotter. Before starting the plotter, he sticks a piece of paper tape on the paper so that it covers the rectangle whose opposite corners are and . After the plotter finishes, he peels off the tape and admires the trails left on it. A trail is any connected curve of positive length drawn on the tape.
While waiting for the plotter to finish, Byteasar wonders how many trails will end up on the tape. Help him answer this question.
Input
The first line contains two integers and (): the order of the bytecurve and the number of queries. Each of the next lines contains three integers , and (, ), describing one glued tape.
Output
Print lines, one per query. Each line contains a single integer: the number of trails drawn on the corresponding tape.
Hint
