luogu#P8463. 「REOI-1」深潜的第六兽

「REOI-1」深潜的第六兽

Background

"None of the 'Seventeen Beasts' can fly. Therefore, after they destroyed the earth, the floating continents could still remain suspended in the sky.

"However, only the 'Sixth Beast of Deep Diving' can, while its main body stays on the ground, still attack the floating continents. It has two abilities: 'Split Proliferation' and 'Rapid Growth'.

"The main body staying on the surface will split into tens of thousands of fragments, which then drift with the wind, waiting to accidentally float onto some floating island. After reaching an island, it will grow rapidly on the spot, and after about six to eight hours, it can occupy and destroy the entire island."

Problem Description

Now there is a 'Sixth Beast'. During one "Split Proliferation", it split into nn fragments. These fragments will fly straight upward. If one fragment encounters a floating island (for convenience of research, we treat it as a line segment in 2D space), it will quickly occupy it, split into two, and then fly straight upward again from the two ends of the floating island.

Fortunately, these are only some unimportant, most barren and uninhabited islands. But if we let them continue to wreak havoc, they will surely deal a devastating blow to those crucial floating islands. Therefore, the officers responsible for eliminating the 'Sixth Beast' decided to use the island they are on as a straight line to define the xx axis, and to use the direction of gravity as the positive direction of the yy axis. They monitored a total of mm floating islands, and determined the positions where those fragments split (the distance from the xx axis is regarded as infinite). They want to know: if we do nothing and let these fragments go, when they reach the officers' position, how many fragments will there finally be.

Note that if a floating island has lil_i equal to rir_i, then it is a point. After the 'Sixth Beast' occupies it, it will still split into two and fly upward from this point.

Hint: As physical objects, floating islands obviously do not overlap.

Brief statement:

In a Cartesian coordinate system, there are mm line segments parallel to the xx axis. The ii-th segment is the segment connecting (li,hi)(l_i,h_i) and (ri,hi)(r_i,h_i). Note that lil_i may equal rir_i, in which case the segment becomes a point.

On the line y=109y=10^9, there are nn points located at (xi,109)(x_i,10^9).

Now these points move downward gradually (the negative direction of the yy axis). If a point touches a segment, it splits into two, and the two new points continue moving downward from the two ends of the segment, respectively.

In particular, if the segment is a point, it splits into 2 at the same position.

Ask: after all initial points undergo the splits caused by the segments, how many points will finally fall onto the xx axis.

Input Format

The first line contains two integers nn and mm.

The next mm lines each contain three integers lil_i, rir_i, hih_i, describing the xx-coordinate of the left endpoint, the xx-coordinate of the right endpoint, and the yy-coordinate of the segment, respectively (0li,ri,hi105liri0 \leq l_i,r_i,h_i \leq 10^5,l_i \leq r_i).

The next line contains nn integers xix_i, where xix_i is the xx-coordinate of the ii-th fragment (0xi1050 \leq x_i \leq 10^5).

Output Format

Output one integer ansans, the number of fragments that finally land on the xx axis. The answer should be taken modulo 998244353998244353.

2 2
1 3 2
2 6 1
3 5
5

Hint

Sample explanation:

Note that the positive direction of the yy axis is the direction of gravity. In the coordinate system, the fragment with xx-coordinate xx first falls onto the segment at y=2y=2, then splits into two and falls downward from 11 and 33. The one at 33 falls onto the segment at y=1y=1, splits into two and falls downward from 22 and 66. The first fragment becomes 33 fragments in total, landing at 1,2,61,2,6. The second fragment becomes 22 fragments in total, landing at 2,62,6.

Subtask Special Constraints Score
1 1n,m10 1\leq n,m \leq 10 10
2 1n,m100 1\leq n,m \leq 100 5
3 1n1041m5×105 1\leq n\leq 10^4, 1\leq m \leq 5\times 10^5 35
4 1n,m5×105 1\leq n,m \leq 5\times 10^5 50

The subtasks of this problem are not bundled for testing.

For 100%100\% of the data, 1n,m5×1051\leq n,m \leq 5\times 10^5, and all numbers are non-negative integers.

Constraints:

Translated by ChatGPT 5