PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000224. Kích thước thành phần liên thông theo khoảng cách (Distance Component Size Query)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Kích thước thành phần liên thông theo khoảng cách (Distance Component Size Query)

Distance Component Size Query

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

An initially empty set SS and a nonnegative integer KK are given. Each value appears at most once. A type-11 operation toggles membership of xx: remove it if present, insert it otherwise.

For a type-22 operation, form an undirected graph on the current values in SS. Distinct vertices u,vu,v are adjacent exactly when ∣u−v∣≤K|u-v|\le K. Count the vertices reachable from xx, including xx itself. Each queried xx is guaranteed to be present at that time.

Input

The first line gives integers Q,KQ,K.

Each of the next QQ lines gives integers t,xt,x: type 11 toggles membership and type 22 requests the component size of xx.

Output

For every type-22 operation, print the current component size on its own line. Type-11 operations produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤Q≤1001\le Q\le 100; 0≤K≤10180\le K\le 10^{18}; 1≤x≤10181\le x\le 10^{18}; t∈{1,2}t\in\{1,2\}; each type-22 query has x∈Sx\in S at query time.
  • Subtask 2 (30 points): 1≤Q≤2⋅1051\le Q\le 2\cdot10^5; 0≤K≤10180\le K\le 10^{18}; 1≤x≤10181\le x\le 10^{18}; t∈{1,2}t\in\{1,2\}; each type-22 query has x∈Sx\in S at query time; each type-11 operation inserts a value not already in SS (no removals).
  • Subtask 3 (50 points): 1≤Q≤2⋅1051\le Q\le 2\cdot10^5; 0≤K≤10180\le K\le 10^{18}; 1≤x≤10181\le x\le 10^{18}; t∈{1,2}t\in\{1,2\}; each type-22 query has x∈Sx\in S at query time.

Examples

Input

8 4
1 2
1 10
2 2
1 6
2 10
1 6
2 10
2 2

Output

1
3
1
1

Explanation

For S={2,10}S=\{2,10\}, the gap 8>48>4 separates the vertices. Inserting 66 creates the edges (2,6)(2,6) and (6,10)(6,10), connecting all three vertices. Removing 66 destroys these edges; the last two queries each address an isolated vertex.