QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726075#6672. Colorful SegmentsFUCKUCUPAC ✓446ms19896kbC++203.8kb2024-11-08 21:31:182024-11-08 21:31:19

Judging History

This is the latest submission verdict.

  • [2024-11-08 21:31:19]
  • Judged
  • Verdict: AC
  • Time: 446ms
  • Memory: 19896kb
  • [2024-11-08 21:31:18]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010, mod = 998244353, inv2 = (mod + 1) / 2;
int T, n, m, num[maxn], tot;
int f[2][maxn], sum[2][maxn], pw[maxn], ipw[maxn];
struct node { int l, r, c; }a[maxn];
struct SegmentTree {
    struct node { int sum, tag; }t[maxn << 2];
    void build(int d, int l, int r) {
      t[d].sum = 0, t[d].tag = 1;
      if(l == r) return;
      int md = l + r >> 1;
      build(d << 1, l, md), build(d << 1 | 1, md + 1, r);
    }
    inline void pushdown(int d) {
      t[d << 1].sum = 1ll * t[d << 1].sum * t[d].tag % mod, t[d << 1 | 1].sum = 1ll * t[d << 1 | 1].sum * t[d].tag % mod;
      t[d << 1].tag = 1ll * t[d << 1].tag * t[d].tag % mod, t[d << 1 | 1].tag = 1ll * t[d << 1 | 1].tag * t[d].tag % mod;
      t[d].tag = 1;
    }
    void modify1(int d, int l, int r, int des, int val) {
      if(l == r) return t[d].sum = val, void();
      if(t[d].tag != 1) pushdown(d);
      int md = l + r >> 1;
      if(des <= md) modify1(d << 1, l, md, des, val);
      else modify1(d << 1 | 1, md + 1, r, des, val);
      t[d].sum = (t[d << 1].sum + t[d << 1 | 1].sum) % mod;
    }
    void modify2(int d, int l, int r, int dl, int dr) {
      if(dl > dr) return;
      if(dl <= l && r <= dr) return t[d].sum = (t[d].sum << 1) % mod, t[d].tag = (t[d].tag << 1) % mod, void();
      if(t[d].tag != 1) pushdown(d);
      int md = l + r >> 1;
      if(dl <= md) modify2(d << 1, l, md, dl, dr);
      if(dr > md) modify2(d << 1 | 1, md + 1, r, dl, dr);
      t[d].sum = (t[d << 1].sum + t[d << 1 | 1].sum) % mod;
    }
    int query(int d, int l, int r, int dl, int dr) {
      if(dl > dr) return 0;
      if(dl <= l && r <= dr) return t[d].sum;
      if(t[d].tag != 1) pushdown(d);
      int md = l + r >> 1, ans = 0;
      if(dl <= md) ans = query(d << 1, l, md, dl, dr);
      if(dr > md) ans = (ans + query(d << 1 | 1, md + 1, r, dl, dr)) % mod;
      return ans;
    }
}t[2];
inline void solve() {
  cin >> n, tot = 0;
  for(int i = 1; i <= n; ++i) cin >> a[i].l >> a[i].r >> a[i].c, num[++tot] = a[i].l, num[++tot] = a[i].r;
  sort(num + 1, num + 1 + tot), tot = unique(num + 1, num + 1 + tot) - num - 1;
  for(int i = 1; i <= n; ++i) {
    a[i].l = lower_bound(num + 1, num + 1 + tot, a[i].l) - num;
    a[i].r = lower_bound(num + 1, num + 1 + tot, a[i].r) - num;
  }
  sort(a + 1, a + 1 + n, [&](auto p, auto q) { return p.r < q.r; });
//  for(int i = 1; i <= n; ++i) cout << a[i].l << ' ' << a[i].r << ' ' << a[i].c << '\n';
  for(int i = 1; i <= tot; ++i) sum[0][i] = sum[1][i] = 0;
  for(int i = 1; i <= n; ++i) ++sum[a[i].c][a[i].r];
  for(int i = 1; i <= tot; ++i) sum[0][i] += sum[0][i - 1], sum[1][i] += sum[1][i - 1];
  t[0].build(1, 1, n), t[1].build(1, 1, n);
  for(int i = 1; i <= n; ++i) f[0][i] = f[1][i] = 0;
  int cnt[2] = {0, 0};
  for(int i = 1; i <= n; ++i) {
    ++cnt[a[i].c];
    f[a[i].c][i] = (t[!a[i].c].query(1, 1, n, 1, sum[!a[i].c][a[i].l - 1]) + pw[cnt[a[i].c] - 1]) % mod;
    t[!a[i].c].modify2(1, 1, n, 1, sum[!a[i].c][a[i].l - 1]);
    t[a[i].c].modify1(1, 1, n, cnt[a[i].c], f[a[i].c][i]);
  }

//  for(int i = 1; i <= tot; ++i) cout << sum[0][i] << ' '; cout << '\n';
//  for(int i = 1; i <= tot; ++i) cout << sum[1][i] << ' '; cout << '\n';
//  for(int i = 1; i <= n; ++i) cout << f[0][i] << ' '; cout << '\n';
//  for(int i = 1; i <= n; ++i) cout << f[1][i] << ' '; cout << '\n';

  int ans = 1;
  for(int i = 1; i <= n; ++i) ans = (ans + f[0][i]) % mod;
  for(int i = 1; i <= n; ++i) ans = (ans + f[1][i]) % mod;
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  n = 1e5, pw[0] = ipw[0] = 1;
  for(int i = 1; i <= n; ++i) pw[i] = (pw[i - 1] << 1) % mod, ipw[i] = 1ll * ipw[i - 1] * inv2 % mod;
  cin >> T;
  while(T--) solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13968kb

input:

2
3
1 5 0
3 6 1
4 7 0
3
1 5 0
7 9 1
3 6 0

output:

5
8

result:

ok 2 number(s): "5 8"

Test #2:

score: 0
Accepted
time: 196ms
memory: 14188kb

input:

11120
9
336470888 481199252 1
642802746 740396295 1
396628655 579721198 0
202647942 971207868 1
46761498 268792718 0
16843338 125908043 1
717268783 787375312 0
519096230 693319712 1
762263554 856168102 1
5
274667941 279198849 0
155191459 421436316 1
140515506 286802932 0
233465964 451394766 1
105650...

output:

107
11
192
24
102
20
14
96
2
8
104
10
9
10
12
8
26
12
268
10
8
4
92
3
2
7
7
34
76
6
16
22
36
8
24
68
46
82
7
92
5
40
8
9
2
2
44
52
68
2
12
64
23
28
16
74
11
4
2
70
2
240
64
40
10
4
2
3
112
2
24
40
38
50
52
4
4
53
46
48
10
4
56
268
22
8
48
42
12
40
12
96
44
8
200
7
8
2
6
35
17
258
44
84
85
10
3
28
2
...

result:

ok 11120 numbers

Test #3:

score: 0
Accepted
time: 446ms
memory: 19836kb

input:

5
100000
54748096 641009859 1
476927808 804928248 1
503158867 627937890 0
645468307 786026685 1
588586447 939887597 0
521365644 710156469 1
11308832 860350786 0
208427221 770562147 0
67590963 726478310 0
135993561 255361535 0
46718075 851555000 1
788412453 946936715 1
706350235 771067386 0
16233727 ...

output:

357530194
516871115
432496137
637312504
617390759

result:

ok 5 number(s): "357530194 516871115 432496137 637312504 617390759"

Test #4:

score: 0
Accepted
time: 292ms
memory: 19668kb

input:

5
100000
848726907 848750009 0
297604744 297778695 0
838103430 838114282 0
39072414 39078626 0
600112362 600483555 0
792680646 792687230 0
580164077 580183653 0
921627432 921685087 0
308067290 308143197 0
111431618 111465177 0
626175211 626270895 0
593284132 593292158 0
497427809 497437386 0
3493551...

output:

538261388
538261388
538261388
538261388
538261388

result:

ok 5 number(s): "538261388 538261388 538261388 538261388 538261388"

Test #5:

score: 0
Accepted
time: 360ms
memory: 19896kb

input:

5
100000
49947 49948 1
44822 44823 0
91204 91205 0
46672 46673 1
18538 18539 1
25486 25487 1
68564 68565 1
63450 63451 1
4849 4850 1
85647 85648 1
6019 6020 0
81496 81497 0
62448 62449 1
50039 50040 1
67911 67912 1
64304 64305 0
68727 68728 0
22340 22341 0
27265 27266 1
74123 74124 0
92270 92271 0
2...

output:

688810885
178370005
333760229
155298895
925722609

result:

ok 5 number(s): "688810885 178370005 333760229 155298895 925722609"