409229: GYM103463 I LTS and rectangular area union

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. LTS and rectangular area uniontime limit per test4.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

In another parallel world, ltslts is a fantastic engineer, he build $$$n$$$ rectangular rooms, numbered from $$$1$$$ to $$$n$$$. From a bird's-eye view, the rooms are arranged on a 2-dimensional plane, with axis-aligned. The southern wall of each room has y-coordinate 0.

The $$$i$$$-th rectangular room has southwest corner $$$(L_i, 0)$$$ and the northeast corner $$$(R_i, H_i)$$$. Since houses often have shared regions (such as a common living/dining area), these rooms may overlap with one another. Due to these houses are built on the mountain, the height of these houses is decreasing.

Specifically, let $$$P_i$$$ be the area of the union of rooms $$$1 \cdots i$$$. Note that the area of the overlap only needs to be calculated once, and that the union might not form a single connected polygon.

Although ltslts is a fantastic engineer, his mathematical ability is very poor. Please help compute the product $$$(P_1 \times P_2 \times P_3 \times \cdots \times P_n)$$$. As this product may be very large, you need compute its value module $$$998244353$$$.

Formally, let $$$M = 998244353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.

It you don't know what is rectangular area union, you just need to remember, the area of the overlap only needs to be calculated once.

For instance, let's consider $$$(L_i, R_i, H_i)$$$ to representing a rectangular, if we have two rectangulars $$$(1, 3, 5)$$$ and $$$(2, 4, 5)$$$, the rectangular area union is $$$15$$$, because the area $$$(2, 3, 5)$$$ is overlap area, just need to calculate once.

Input

The first line contains a single integer $$$n(1 \leq n \leq 10^6)$$$, denoting the number of rooms.

In the next $$$n$$$ lines, each line contains three integers $$$L_i, R_i, H_i(1 \leq L_i, R_i, H_i \leq 10^9),$$$ representing the $$$i$$$-th rectangular.

It is guaranteed that $$$H_1 \geq H_2 \geq \cdots \geq H_n$$$ and $$$L_i < R_i$$$.

Output

Print a single integer in one line: the product $$$(P_1 \times P_2 \times P_3 \times \cdots \times P_n)$$$ module $$$998244353$$$.

ExampleInput
2
1 4 5
2 3 5
Output
225

加入题单

算法标签: