luogu#P14977. [USACO26JAN1] Lineup Queries S
[USACO26JAN1] Lineup Queries S
Problem Description
There is a line of cows, initially (i.e. at time ) containing only cow at position (here, a cow is at position if there are cows in front of it). At time for , the cow at position 0 moves to position , every cow in positions moves forward one position, and cow joins the line at the end of the line (position ).
Answer () independent queries, each of one of the following types:
- At what position is cow immediately after time ()?
- Which cow is at position immediately after time ()?
Input Format
The first line contains , the number of queries.
The next lines each contain three integers specifying a query either of the form " " or " ".
Output Format
Output the answer to each query on a separate line.
2
1 4 9
2 2 9
2
4
22
1 0 9
1 1 9
1 2 9
1 3 9
1 4 9
1 5 9
1 6 9
1 7 9
1 8 9
1 9 9
2 0 9
2 1 9
2 2 9
2 3 9
2 4 9
2 5 9
2 6 9
2 7 9
2 8 9
2 9 9
1 0 1000000000000000000
2 0 1000000000000000000
1
3
0
4
2
5
6
7
8
9
2
0
4
1
3
5
6
7
8
9
483992463350322770
148148148148148148
Hint
Lineups immediately after various times:
t = 0 | 0
t = 1 | 0 1
t = 2 | 1 0 2
t = 3 | 0 1 2 3
t = 4 | 1 2 0 3 4
t = 5 | 2 0 1 3 4 5
t = 6 | 0 1 3 2 4 5 6
t = 7 | 1 3 2 0 4 5 6 7
t = 8 | 3 2 0 4 1 5 6 7 8
t = 9 | 2 0 4 1 3 5 6 7 8 9
Immediately after , the location of cow is , and the cow located at position is .
- Input 3:
- Input 4:
- Inputs 5-8: All queries are of type 1.
- Inputs 9-12: All queries are of type 2.