Telepanting
题意翻译
### **【题目大意】**
有一只初始在位置 $0$ 的蚂蚁,它每秒钟会向右走 $1$ 一个单位长度。
在地图上有 $n$ 个虫洞,第 $i$ 个虫洞在位置 $x_{i}$,如果它是活动的,它就会把蚂蚁送回到位置 $y_{i}(y_{i}<x_{i})$。
初始时每个虫洞有一个参数 $s_{i}$,$s_{i}$ 是 $0$ 表示虫洞是初始静止的,而 $1$ 表示虫洞初始是活动的。
当蚂蚁踩到虫洞 $i$ 时:
- 如果这个虫洞是静止的,那么此虫洞会变成活动的,但是蚂蚁的位置不改变。
- 如果这个虫洞是活动,那么此虫洞将变成静止,且会把蚂蚁送回 $y_{i}$ 位置,而接下来蚂蚁将保持向右每秒 $1$ 个单位的速度前进(即下一秒它会到位置 $y_{i}+1$)。
现在我们想知道,这只蚂蚁需要多少时间才能到位置 $(x_{n}+1)$ 呢?**答案对 $998244353$ 取模**。
### 【输入格式】
第一行 $1$ 个数 $n$,表示虫洞的数量。
接下来 $n$ 行每行 $3$ 个整数,$x_{i},y_{i},s_{i}$,含义见题面。
保证 $\forall i \in [1,n), \quad x_{i}<x_{i+1}$,且 $x_{1 \cdots n},y_{1 \cdots n}$ 两两不同。
### 【输出格式】
一行一个整数,表示答案。
**答案对 $998244353$ 取模**。
### 【数据范围】
- $1 \leq n \leq 2 \times 10^{5}$。
- $\forall i \in [1,n], \quad 1 \leq y_{i}<x_{i} \leq 1 \times 10^{9},s_{i} \in \{0,1 \}$。
Translated by @HPXXZYY
题目描述
An ant moves on the real line with constant speed of $ 1 $ unit per second. It starts at $ 0 $ and always moves to the right (so its position increases by $ 1 $ each second).
There are $ n $ portals, the $ i $ -th of which is located at position $ x_i $ and teleports to position $ y_i < x_i $ . Each portal can be either active or inactive. The initial state of the $ i $ -th portal is determined by $ s_i $ : if $ s_i=0 $ then the $ i $ -th portal is initially inactive, if $ s_i=1 $ then the $ i $ -th portal is initially active. When the ant travels through a portal (i.e., when its position coincides with the position of a portal):
- if the portal is inactive, it becomes active (in this case the path of the ant is not affected);
- if the portal is active, it becomes inactive and the ant is instantly teleported to the position $ y_i $ , where it keeps on moving as normal.
How long (from the instant it starts moving) does it take for the ant to reach the position $ x_n + 1 $ ? It can be shown that this happens in a finite amount of time. Since the answer may be very large, compute it modulo $ 998\,244\,353 $ .
输入输出格式
输入格式
The first line contains the integer $ n $ ( $ 1\le n\le 2\cdot 10^5 $ ) — the number of portals.
The $ i $ -th of the next $ n $ lines contains three integers $ x_i $ , $ y_i $ and $ s_i $ ( $ 1\le y_i < x_i\le 10^9 $ , $ s_i\in\{0,1\} $ ) — the position of the $ i $ -th portal, the position where the ant is teleported when it travels through the $ i $ -th portal (if it is active), and the initial state of the $ i $ -th portal.
The positions of the portals are strictly increasing, that is $ x_1<x_2<\cdots<x_n $ . It is guaranteed that the $ 2n $ integers $ x_1, \, x_2, \, \dots, \, x_n, \, y_1, \, y_2, \, \dots, \, y_n $ are all distinct.
输出格式
Output the amount of time elapsed, in seconds, from the instant the ant starts moving to the instant it reaches the position $ x_n+1 $ . Since the answer may be very large, output it modulo $ 998\,244\,353 $ .
输入输出样例
输入样例 #1
4
3 2 0
6 5 1
7 4 0
8 1 1
输出样例 #1
23
输入样例 #2
1
454971987 406874902 1
输出样例 #2
503069073
输入样例 #3
5
243385510 42245605 0
644426565 574769163 0
708622105 208990040 0
786625660 616437691 0
899754846 382774619 0
输出样例 #3
899754847
输入样例 #4
5
200000000 100000000 1
600000000 400000000 0
800000000 300000000 0
900000000 700000000 1
1000000000 500000000 0
输出样例 #4
3511295
说明
Explanation of the first sample: The ant moves as follows (a curvy arrow denotes a teleporting, a straight arrow denotes normal movement with speed $ 1 $ and the time spent during the movement is written above the arrow). $ $$$ 0 \stackrel{6}{\longrightarrow} 6 \leadsto 5 \stackrel{3}{\longrightarrow} 8 \leadsto 1 \stackrel{2}{\longrightarrow} 3 \leadsto 2 \stackrel{4}{\longrightarrow} 6 \leadsto 5 \stackrel{2}{\longrightarrow} 7 \leadsto 4 \stackrel{2}{\longrightarrow} 6 \leadsto 5 \stackrel{4}{\longrightarrow} 9 $ $ Notice that the total time is $ 6+3+2+4+2+2+4=23 $ .</p><p><span class="tex-font-style-bf">Explanation of the second sample:</span> The ant moves as follows (a curvy arrow denotes a teleporting, a straight arrow denotes normal movement with speed $ 1 $ and the time spent during the movement is written above the arrow). $ $ 0 \stackrel{454971987}{\longrightarrow} 454971987 \leadsto 406874902 \stackrel{48097086}{\longrightarrow} 454971988 $ $ Notice that the total time is $ 454971987+48097086=503069073 $ .</p><p><span class="tex-font-style-bf">Explanation of the third sample:</span> Since all portals are initially off, the ant will not be teleported and will go straight from $ 0 $ to $ x\_n+1=899754846+1=899754847$$$.