PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000029. Cắt thanh gỗ (Cutting Woods)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Cắt thanh gỗ (Cutting Woods)
Cutting Woods
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A timber has length , with endpoints at coordinates and . Process the following operations in order: 1 x cuts the timber at mark ; 2 x` asks for the length of the current piece containing mark . It is guaranteed that no cut has been made at before either kind of operation.
Input
The first line contains . Each of the next lines contains , where is or .
Output
For each query of type 2, print the requested timber length.
Subtasks
- Subtask 1 (20 points): ; ; ; ; the mark has not previously been cut.
- Subtask 2 (30 points): ; ; ; ; the mark has not previously been cut.
- Subtask 3 (50 points): ; ; ; ; the mark has not previously been cut.
Examples
Input
5 3
2 2
1 3
2 2
Output
5
3
Explanation
Initially the timber has length 5. After cutting at 3, position 2 lies in [0,3], whose length is 3.