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

Bài tập thuộc lộ trình

2 lộ trình

Cắt thanh gỗ (Cutting Woods)

Cutting Woods

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A timber has length LL, with endpoints at coordinates 00 and LL. Process the following operations in order: 1 x cuts the timber at mark xx; 2 x` asks for the length of the current piece containing mark xx. It is guaranteed that no cut has been made at xx before either kind of operation.

Input

The first line contains L,QL,Q. Each of the next QQ lines contains c,xc,x, where cc is 11 or 22.

Output

For each query of type 2, print the requested timber length.

Subtasks

  • Subtask 1 (20 points): 1≤L≤1091\le L\le10^9; 1≤Q≤201\le Q\le 20; 1≤x<L1\le x<L; c∈{1,2}c\in\{1,2\}; the mark xx has not previously been cut.
  • Subtask 2 (30 points): 1≤L≤1091\le L\le10^9; 1≤Q≤8001\le Q\le 800; 1≤x<L1\le x<L; c∈{1,2}c\in\{1,2\}; the mark xx has not previously been cut.
  • Subtask 3 (50 points): 1≤L≤1091\le L\le10^9; 1≤Q≤2000001\le Q\le 200000; 1≤x<L1\le x<L; c∈{1,2}c\in\{1,2\}; the mark xx 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.