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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
| #include <iostream> #include <ctime> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <climits> #include <queue> #include <set> #include <cmath> #include <map> #include <bitset> #include <fstream> #include <tr1/unordered_map> #include <assert.h>
#define x first #define y second #define y0 Y0 #define y1 Y1 #define mp make_pair #define pb push_back #define DEBUG(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long LL; typedef long double LD; typedef pair <int, int> pii;
template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> inline T read () { T sum = 0, fl = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1; for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0'; return sum * fl; }
inline void proc_status () { ifstream t ("/proc/self/status"); cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl; }
const int MAXN = 1e5; const int MOD = 998244353;
namespace MATH { inline void ADD (int &a, int b) { if ((a += b) >= MOD) a -= MOD; }
inline int Pow (int a, int b) { int ans = 1; for (int i = b; i; i >>= 1, a = (LL) a * a % MOD) if (i & 1) ans = (LL) ans * a % MOD; return ans; } }
using namespace MATH;
int N; struct info { int x, v, p; inline void read () { x = ::read<int>(), v = ::read<int>(), p = (LL) ::read<int>() * Pow (100, MOD - 2) % MOD; }
} A[MAXN + 5];
struct matrix // 右1左0 { int A[2][2];
inline matrix () { memset (A, 0, sizeof A); }
inline int* operator [] (const int &x) { return A[x]; }
inline matrix operator * (const matrix &rhs) const { matrix now; for (int i = 0; i < 2; ++i) for (int k = 0; k < 2; ++k) if (A[i][k]) for (int j = 0; j < 2; ++j) ADD (now.A[i][j], (LL) A[i][k] * rhs.A[k][j] % MOD); return now; } };
namespace SEG { #define mid ((l + r) >> 1) #define ls o << 1 #define rs o << 1 | 1 #define lson ls, l, mid #define rson rs, mid + 1, r const int MAX_NODE = MAXN * 4;
matrix node[MAX_NODE + 5];
inline void push_up (int o) { node[o] = node[ls] * node[rs]; }
inline void build (int o, int l, int r) { if (l == r) { int p = A[l].p; node[o][0][0] = node[o][1][0] = (1 - p + MOD) % MOD; node[o][0][1] = node[o][1][1] = p; return ; } build (lson), build (rson); push_up (o); }
inline void modify (int o, int l, int r, int x, int s0, int s1) { if (l == r) { node[o][s0][s1] = 0; return ; } if (x <= mid) modify (lson, x, s0, s1); else modify (rson, x, s0, s1); push_up (o); }
inline int query () { return (node[1][0][0] + node[1][0][1]) % MOD; }
#undef mid }
struct point { int x, s0, s1, t; LD tt;
inline point (int _x = 0, int _s0 = 0, int _s1 = 0, int _t = 0, LD _tt = 0) { x = _x, s0 = _s0, s1 = _s1, t = _t, tt = _tt; } };
inline int cmp_t (point a, point b) { return a.tt < b.tt; }
vector <point> vec;
inline void Init () { for (int i = 1; i < N; ++i) { info l = A[i], r = A[i + 1]; if (l.p != 0 && r.p != 1) vec.pb (point (i + 1, 1, 0, (LL) (r.x - l.x) * Pow (l.v + r.v, MOD - 2) % MOD, (LD) (r.x - l.x) / (l.v + r.v))); if (l.p != 0 && r.p != 0 && l.v > r.v) vec.pb (point (i + 1, 1, 1, (LL) (r.x - l.x) * Pow (l.v - r.v, MOD - 2) % MOD, (LD) (r.x - l.x) / (l.v - r.v))); if (l.p != 1 && r.p != 1 && l.v < r.v) vec.pb (point (i + 1, 0, 0, (LL) (r.x - l.x) * Pow (r.v - l.v, MOD - 2) % MOD, (LD) (r.x - l.x) / (r.v - l.v))); }
sort (vec.begin(), vec.end(), cmp_t);
SEG :: build (1, 1, N); }
inline void Solve () { if (N == 1) return void (puts("0")); Init ();
int ans = 0, lst = 1; for (int i = 0; i < vec.size(); ++i) { int x = vec[i].x, s0 = vec[i].s0, s1 = vec[i].s1, t = vec[i].t; SEG :: modify (1, 1, N, x, s0, s1); int p = (lst - SEG :: query () + MOD) % MOD; ADD (ans, (LL) p * t % MOD); lst = SEG :: query (); }
cout << ans << endl; }
inline void Input () { N = read<int>(); for (int i = 1; i <= N; ++i) A[i].read(); }
int main () {
#ifdef hk_cnyali freopen("F.in", "r", stdin); freopen("F.out", "w", stdout); #endif
Input (); Solve ();
return 0; }
|