Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define endl '\n'
- const int N = 1e5 + 10;
- const ll mod = 998244353;
- class Segment {
- private:
- struct Node {
- ll sum, tag;
- } node[N << 2];
- public:
- void push_up (int p) {
- node[p].sum = (node[p << 1].sum + node[p << 1 | 1].sum) % mod;
- }
- void build (int s, int t, int p) {
- node[p].tag = 1;
- if (s == t) {
- node[p].sum = 0;
- return;
- }
- int mid = (s + t) >> 1;
- build(s, mid, p << 1);
- build(mid + 1, t, p << 1 | 1);
- push_up(p);
- }
- void push_down (int p) {
- if (node[p].tag != 1) {
- int ls = p << 1, rs = p << 1 | 1;
- node[ls].tag = node[ls].tag * node[p].tag % mod;
- node[ls].sum = node[ls].sum * node[p].tag % mod;
- node[rs].tag = node[rs].tag * node[p].tag % mod;
- node[rs].sum = node[rs].sum * node[p].tag % mod;
- node[p].tag = 1;
- }
- }
- void update (int x, ll val, int s, int t, int p) {
- if (s == t) {
- node[p].sum = val;
- return;
- }
- int mid = (s + t) >> 1;
- push_down(p);
- if (x <= mid) update(x, val, s, mid, p << 1);
- else update(x, val, mid + 1, t, p << 1 | 1);
- push_up(p);
- return;
- }
- void muti (int l, int r, int s, int t, int p) {
- if (l <= s && t <= r) {
- node[p].sum = node[p].sum * 2 % mod;
- node[p].tag = node[p].tag * 2 % mod;
- return;
- }
- int mid = (s + t) >> 1;
- push_down(p);
- if (l <= mid) muti(l, r, s, mid, p << 1);
- if (mid < r) muti(l, r, mid + 1, t, p << 1 | 1);
- push_up(p);
- return;
- }
- ll query (int l, int r, int s, int t, int p) {
- if (l <= s && t <= r) return node[p].sum;
- int mid = (s + t) >> 1;
- push_down(p);
- ll res = 0;
- if (l <= mid) res = query(l, r, s, mid, p << 1);
- if (mid < r) res += query(l, r, mid + 1, t, p << 1);
- return res % mod;
- }
- };
- Segment segt[2];
- int n;
- struct str {
- int l, r, col;
- } seg[N];
- void solve() {
- cin >> n;
- for (int i = 1; i <= n; i ++) {
- cin >> seg[i].l >> seg[i].r >> seg[i].col;
- }
- sort(seg + 1, seg + 1 + n, [&](str x, str y) {
- if (x.r == y.r) return x.l < y.l;
- return x.r < y.r;
- });
- segt[0].build(0, n, 1);
- segt[1].build(0, n, 1);
- segt[0].update(0, 1, 0, n, 1);
- segt[1].update(0, 1, 0, n, 1);
- ll ans = 1;
- for (int i = 1; i <= n; i ++) {
- int l = 0, r = i - 1;
- while (l < r) {
- int mid = r - ((r - l) >> 1);
- if (seg[mid].r >= seg[i].l) r = mid - 1;
- else l = mid;
- }
- int c = seg[i].col;
- ll val = segt[c ^ 1].query(0, l, 0, n, 1);
- ans = (ans + val) % mod;
- segt[c].update(i, val, 0, n, 1);
- segt[c ^ 1].muti(0, l, 0, n, 1);
- cout << seg[i].l << ' ' << seg[i].r << ' ' << seg[i].col << ": " << l << ' ' << val << endl;
- }
- cout << ans << endl;
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int _ = 1;
- cin >> _;
- while(_--)
- solve();
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement