1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| const int N = 100005; const int Mod = 998244353;
class Matrix { public: int a[2][2]; Matrix() { a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0; } Matrix & operator =(Matrix i) { a[0][0] = i.a[0][0]; a[0][1] = i.a[0][1]; a[1][0] = i.a[1][0]; a[1][1] = i.a[1][1]; return *this; } Matrix operator *(Matrix i) { Matrix ans; ans.a[0][0] = (a[0][0] * 1ll * i.a[0][0] + a[0][1] * 1ll * i.a[1][0]) % Mod; ans.a[0][1] = (a[0][0] * 1ll * i.a[0][1] + a[0][1] * 1ll * i.a[1][1]) % Mod; ans.a[1][0] = (a[1][0] * 1ll * i.a[0][0] + a[1][1] * 1ll * i.a[1][0]) % Mod; ans.a[1][1] = (a[1][0] * 1ll * i.a[0][1] + a[1][1] * 1ll * i.a[1][1]) % Mod; return ans; } }; class Query { public: int s, v, x, a, b; Query(int s = 0, int v = 0, int x = 0, int a = 0, int b = 0) : s(s), v(v), x(x), a(a), b(b) {} bool operator<(Query i) { return s * 1ll * i.v < i.s * 1ll * v; } };
int pow(int a, int b, int m); void build(int x, int xl, int xr); void update(int x, int xl, int xr, int ux);
Matrix sum[N << 2]; Matrix m[N]; int x[N], v[N], p[N]; Query q[N << 1]; int cnt; int n;
int main () { read(n); int iv = pow(100, Mod - 2, Mod); for (int i = 1; i <= n; ++i) { read(x[i]), read(v[i]), read(p[i]); p[i] = p[i] * 1ll * iv % Mod; } for (int i = 1; i <= n; ++i) { m[i].a[0][0] = m[i].a[1][0] = (Mod + 1 - p[i]) % Mod; m[i].a[0][1] = m[i].a[1][1] = p[i]; } build(1, 1, n); for (int i = 2; i <= n; ++i) { q[++cnt] = Query(x[i] - x[i - 1], v[i] + v[i - 1], i, 1, 0); if (v[i] > v[i - 1]) { q[++cnt] = Query(x[i] - x[i - 1], v[i] - v[i - 1], i, 0, 0); } if (v[i] < v[i - 1]) { q[++cnt] = Query(x[i] - x[i - 1], v[i - 1] - v[i], i, 1, 1); } } std::sort(q + 1, q + cnt + 1); int res = 0; for (int i = 1; i <= cnt; ++i) { Matrix m1, m2; m1 = m[q[i].x]; m2.a[q[i].a][q[i].b] = m1.a[q[i].a][q[i].b]; m[q[i].x] = m2; update(1, 1, n, q[i].x); int tim = q[i].s * 1ll * pow(q[i].v, Mod - 2, Mod) % Mod; res = (res + (sum[1].a[0][0] + sum[1].a[0][1]) * 1ll * tim % Mod) % Mod; m1.a[q[i].a][q[i].b] = 0; m[q[i].x] = m1; update(1, 1, n, q[i].x); } write(res), EL; return 0; }
int pow(int a, int b, int m) { int ans = 1, now = a; while (b) { if (b & 1) { ans = ans * 1ll * now % m; } now = now * 1ll * now % m; b >>= 1; } return ans; } void pushup(int x) { sum[x] = sum[x << 1] * sum[x << 1 | 1]; } void build(int x, int xl, int xr) { if (xl == xr) { sum[x] = m[xl]; return; } int xm = (xl + xr) >> 1; build(x << 1, xl, xm); build(x << 1 | 1, xm + 1, xr); pushup(x); } void update(int x, int xl, int xr, int ux) { if (xl == xr) { sum[x] = m[xl]; return; } int xm = (xl + xr) >> 1; if (ux <= xm) { update(x << 1, xl, xm, ux); } else { update(x << 1 | 1, xm + 1, xr, ux); } pushup(x); }
|