CF1552F.Telepanting
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 xi and teleports to position yi<xi. Each portal can be either active or inactive. The initial state of the i-th portal is determined by si: if si=0 then the i-th portal is initially inactive, if si=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 yi, 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 xn+1? It can be shown that this happens in a finite amount of time. Since the answer may be very large, compute it modulo 998244353.
一只蚂蚁在实数轴上以恒定速度 1 单位/秒移动。它从位置 0 出发,始终向右移动(即其位置每秒增加 1)。
共有 n 个传送门,其中第 i 个传送门位于位置 xi,并传送到位置 yi<xi。每个传送门可以处于激活或未激活状态。第 i 个传送门的初始状态由 si 决定:若 si=0,则该传送门初始为未激活;若 si=1,则该传送门初始为激活。当蚂蚁经过某个传送门(即其位置恰好等于该传送门的位置)时:
- 若该传送门处于未激活状态,则它变为激活状态(此时蚂蚁的运动路径不受影响);
- 若该传送门处于激活状态,则它变为未激活状态,且蚂蚁立即被传送到位置 yi,之后继续按常规方式向右移动。
从蚂蚁开始移动的时刻起,它需要多长时间才能到达位置 xn+1?可以证明该过程必在有限时间内完成。由于答案可能非常大,请对 998244353 取模输出结果。
输入格式
The first line contains the integer n (1≤n≤2⋅105) — the number of portals.
The i-th of the next n lines contains three integers xi, yi and si (1≤yi<xi≤109, si∈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 x1<x2<⋯<xn. It is guaranteed that the 2n integers x1,x2,…,xn,y1,y2,…,yn are all distinct.
第一行包含一个整数 n(1≤n≤2⋅105)—— 表示传送门的数量。
接下来的 n 行中,第 i 行包含三个整数 xi、yi 和 si(1≤yi<xi≤109,si∈{0,1})—— 分别表示第 i 个传送门的位置、蚂蚁穿过该传送门(当其处于激活状态时)后被传送到的位置,以及该传送门的初始状态。
传送门的位置严格递增,即 x1<x2<⋯<xn。保证 2n 个整数 x1,x2,…,xn,y1,y2,…,yn 两两互不相同。
输出格式
Output the amount of time elapsed, in seconds, from the instant the ant starts moving to the instant it reaches the position xn+1. Since the answer may be very large, output it modulo 998244353.
输出蚂蚁从开始移动到到达位置 xn+1 所经过的时间(单位:秒)。由于答案可能非常大,请对 998244353 取模后输出。
输入输出样例
输入#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.
Explanation of the second 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{454971987}{\longrightarrow} 454971987 \leadsto 406874902 \stackrel{48097086}{\longrightarrow} 454971988 $$ Notice that the total time is 454971987+48097086=503069073.
Explanation of the third sample: Since all portals are initially off, the ant will not be teleported and will go straight from 0 to xn+1=899754846+1=899754847.
第一个样例的解释:蚂蚁的移动过程如下(弯曲箭头表示传送,直线箭头表示以速度 1 的正常移动,箭头上方的数字表示该次移动所花费的时间):
0stackrel6longrightarrow6leadsto5stackrel3longrightarrow8leadsto1stackrel2longrightarrow3leadsto2stackrel4longrightarrow6leadsto5stackrel2longrightarrow7leadsto4stackrel2longrightarrow6leadsto5stackrel4longrightarrow9
注意,总时间为 6+3+2+4+2+2+4=23。
第二个样例的解释:蚂蚁的移动过程如下(弯曲箭头表示传送,直线箭头表示以速度 1 的正常移动,箭头上方的数字表示该次移动所花费的时间):
0stackrel454971987longrightarrow454971987leadsto406874902stackrel48097086longrightarrow454971988
注意,总时间为 454971987+48097086=503069073。
第三个样例的解释:由于所有传送门初始均处于关闭状态,蚂蚁不会被传送,而是直接从 0 走到 xn+1=899754846+1=899754847。
输入解题思路,AI测评打分。不知道怎么写?