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

#SP0000254. Những người du lịch (Tourists)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những người du lịch (Tourists)

Tourists

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A park has two parallel walking paths on the lines x=−1x=-1 and x=1x=1. For each pair of tourists, the two people simultaneously depart from (−1,0)(-1,0) and (1,0)(1,0) at time qq, walking in the positive OyOy direction at speed 11 distance unit per second. Thus both tourists are at height ss after ss seconds.

There are mm walls. Wall ii is the closed line segment from (0,li)(0,l_i) to (0,ri)(0,r_i); it appears instantaneously at time tit_i and remains present thereafter. Walls may overlap or coincide.

The two tourists cannot see each other whenever the segment connecting their current positions intersects at least one wall already present, including touching an endpoint. For each departure time qjq_j, find the total duration in seconds for which the two tourists cannot see each other. Each pair of tourists is treated independently; all walls follow the same appearance schedule.

Input

The first line contains two integers n,mn,m, the numbers of tourist pairs and walls.

Each of the next mm lines contains three integers li,ri,til_i,r_i,t_i, describing the vertical endpoints and appearance time of wall ii.

The last line contains exactly nn distinct, strictly increasing departure times q1,q2,…,qnq_1,q_2,\ldots,q_n.

Output

Print exactly nn lines, one 64-bit integer per line: the total duration of invisibility for the pair departing at qjq_j, in the order j=1,2,…,nj=1,2,\ldots,n.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤m≤201\le m\le 20; 0≤li<ri≤10000\le l_i<r_i\le 1000; 0≤ti≤10000\le t_i\le 1000 for all 1≤i≤m1\le i\le m; 0≤q1<q2<⋯<qn≤10000\le q_1<q_2<\cdots<q_n\le 1000.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤m≤20001\le m\le 2000; 0≤li<ri≤1060\le l_i<r_i\le 10^6; 0≤ti≤1060\le t_i\le 10^6 for all 1≤i≤m1\le i\le m; 0≤q1<q2<⋯<qn≤1060\le q_1<q_2<\cdots<q_n\le 10^6.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le 10^5; 1≤m≤1051\le m\le 10^5; 0≤li<ri≤1090\le l_i<r_i\le 10^9; 0≤ti≤1090\le t_i\le 10^9 for all 1≤i≤m1\le i\le m; 0≤q1<q2<⋯<qn≤1090\le q_1<q_2<\cdots<q_n\le 10^9.

Examples

Input

2 2
1 4 3
3 6 5
0 1

Output

2
4

Explanation

There are two walls: [1,4][1,4] appears at time 33, and [3,6][3,6] at time 55.

  • For departure time q1=0q_1=0, the tourists reach height 33 at time 33 and the first wall blocks their view until they pass height 44, for 11 second. At time 55 they are at height 55; the second wall blocks their view until height 66, for another 11 second. The answer is 22.
  • For q2=1q_2=1, the tourists reach height 22 at time 33. The first wall blocks heights from 22 through 44, for 22 seconds. At time 55 they reach height 44, and the second wall blocks their view until height 66, for another 22 seconds. The answer is 44.

The inclusion of interval endpoints does not affect duration.