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

#PS0000271. Phân biệt đoạn đóng và đoạn nửa mở (Closed and Half-open Intervals)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phân biệt đoạn đóng và đoạn nửa mở (Closed and Half-open Intervals)

Closed and Half-open Intervals

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given NN intervals on the integer number line, type t=0t=0 includes integers l≤x≤rl\le x\le r, and type t=1t=1 includes integers l≤x<rl\le x<r. For each query xx, count intervals containing it. Duplicate intervals count separately. A half-open interval [l,l)[l,l) is empty; a closed interval [l,l][l,l] contains one point.

Input

First line: N,QN,Q. Next NN lines: t,l,rt,l,r. Last line: QQ integers x1,…,xQx_1,\ldots,x_Q.

Output

Print QQ integers on one line in query order.

Subtasks

  • Subtask 1 (20 points): 1≤N,Q≤1001\le N,Q\le 100; t∈{0,1}t\in\{0,1\}; −100≤l≤r≤100-100\le l\le r\le 100; ∣xj∣≤100|x_j|\le 100.
  • Subtask 2 (30 points): 1≤N,Q≤2000001\le N,Q\le 200000; t∈{0,1}t\in\{0,1\}; −1012≤l≤r≤1012-10^{12}\le l\le r\le 10^{12}; ∣xj∣≤1012|x_j|\le 10^{12}; t=0t=0 for every interval.
  • Subtask 3 (50 points): 1≤N,Q≤2000001\le N,Q\le 200000; t∈{0,1}t\in\{0,1\}; −1012≤l≤r≤1012-10^{12}\le l\le r\le 10^{12}; ∣xj∣≤1012|x_j|\le 10^{12}.

Example 1

Input

4 5
0 1 3
1 1 3
0 3 3
1 3 3
0 1 2 3 4

Output

0 2 2 2 0

Explanation

No interval contains 0 or 4. Both first intervals contain 1 and 2. At 3 only the two closed intervals count; [3,3)[3,3) is empty.

Example 2

Input

3 4
0 -2 0
1 -2 0
1 0 2
-2 -1 0 2

Output

2 2 2 0

Explanation

At -2 and -1 the first two intervals count; at 0 the first closed and third half-open interval count; 2 is excluded.