답안 #1051172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051172 2024-08-09T21:50:56 Z Trent 디지털 회로 (IOI22_circuit) C++17
89 / 100
3000 ms 28640 KB
#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;

const ll MOD = 1000002022;
const int MN = 1e5 + 10;
vvi ch;
vll w;
int n, m;
vll totPos;
void sdfs(int c) {
  totPos[c] = c >= n ? 1 : ch[c].size();
  for(int i : ch[c]) {
    sdfs(i);
    totPos[c] = totPos[c] * totPos[i] % MOD;
  }
}
void dfs(int c, ll cw) {
  w[c] = cw;
  for(int i : ch[c]) {
    ll wCh = cw;
    for(int j : ch[c]) if(j != i) wCh = wCh * totPos[j] % MOD;
    dfs(i, wCh);
  }
}

vb tgl;
struct node {
  ll tot, iTot;
  bool lz;
};
const int MM = 1e5 + 10, ME = 4 * MM;
node seg[ME];
void push(int c) {
  if(seg[c].lz) {
    if(2 * c + 1 < ME) {
      swap(seg[2*c].tot, seg[2*c].iTot);
      seg[2*c].lz = !seg[2*c].lz;
      swap(seg[2*c+1].tot, seg[2*c+1].iTot);
      seg[2*c+1].lz = !seg[2*c+1].lz;
    }
    seg[c].lz = false;
  }
}
void build(int v, int nl, int nr) {
  if(nl == nr) {
    if(tgl[nl + n]) seg[v].tot = w[nl+n], seg[v].iTot = 0;
    else seg[v].tot = 0, seg[v].iTot = w[nl+n];
  } else {
    int mid = (nl+nr)/2;
    build(2*v, nl, mid);
    build(2*v+1, mid+1, nr);
    seg[v].tot = (seg[2*v].tot+seg[2*v+1].tot) % MOD;
    seg[v].iTot = (seg[2*v].iTot+seg[2*v+1].iTot) % MOD;
  }
}
void upd(int v, int nl, int nr, int l, int r) {
  push(v);
  if(l > r) return;
  if(l == nl && r == nr) {
    swap(seg[v].tot, seg[v].iTot);
    assert(!seg[v].lz);
    seg[v].lz = true;
  } else {
    int mid = (nl+nr)/2;
    upd(2*v, nl, mid, l, min(mid, r));
    upd(2*v+1, mid+1, nr, max(mid+1,l), r);
    seg[v].tot = (seg[2*v].tot + seg[2*v+1].tot) % MOD;
    seg[v].iTot = (seg[2*v].iTot + seg[2*v+1].iTot) % MOD;
  }
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  ::n = N, ::m = M;
  ch.resize(N+M);
  totPos.resize(N+M);
  w.resize(N+M);
  tgl.resize(N+M);

  REP(i, 1, N+M) ch[P[i]].push_back(i);
  sdfs(0);
  dfs(0, 1);
  forR(i, M) tgl[N+i] = A[i] == 1;
  build(1, 0, m-1);
}

int count_ways(int L, int R) {
  upd(1, 0, m-1, L-n, R-n);
  ll tot = seg[1].tot;
  return (int) tot;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 496 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 496 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 496 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 5 ms 600 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 7544 KB Output is correct
2 Correct 542 ms 14964 KB Output is correct
3 Correct 585 ms 15000 KB Output is correct
4 Correct 587 ms 14572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 7544 KB Output is correct
2 Correct 542 ms 14964 KB Output is correct
3 Correct 585 ms 15000 KB Output is correct
4 Correct 587 ms 14572 KB Output is correct
5 Correct 454 ms 7676 KB Output is correct
6 Correct 637 ms 14568 KB Output is correct
7 Correct 636 ms 14572 KB Output is correct
8 Correct 549 ms 13400 KB Output is correct
9 Correct 273 ms 856 KB Output is correct
10 Correct 527 ms 3160 KB Output is correct
11 Correct 513 ms 3160 KB Output is correct
12 Correct 529 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 373 ms 7544 KB Output is correct
14 Correct 542 ms 14964 KB Output is correct
15 Correct 585 ms 15000 KB Output is correct
16 Correct 587 ms 14572 KB Output is correct
17 Correct 454 ms 7676 KB Output is correct
18 Correct 637 ms 14568 KB Output is correct
19 Correct 636 ms 14572 KB Output is correct
20 Correct 549 ms 13400 KB Output is correct
21 Correct 273 ms 856 KB Output is correct
22 Correct 527 ms 3160 KB Output is correct
23 Correct 513 ms 3160 KB Output is correct
24 Correct 529 ms 3160 KB Output is correct
25 Correct 613 ms 21772 KB Output is correct
26 Correct 683 ms 21992 KB Output is correct
27 Correct 654 ms 22272 KB Output is correct
28 Correct 501 ms 20048 KB Output is correct
29 Correct 603 ms 28640 KB Output is correct
30 Correct 558 ms 26200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 496 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 496 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 5 ms 600 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 410 ms 2904 KB Output is correct
44 Correct 548 ms 2904 KB Output is correct
45 Correct 542 ms 2904 KB Output is correct
46 Correct 478 ms 3160 KB Output is correct
47 Correct 527 ms 3160 KB Output is correct
48 Correct 548 ms 3160 KB Output is correct
49 Correct 562 ms 3160 KB Output is correct
50 Correct 553 ms 3160 KB Output is correct
51 Correct 642 ms 2968 KB Output is correct
52 Correct 652 ms 2964 KB Output is correct
53 Correct 486 ms 1120 KB Output is correct
54 Correct 566 ms 3160 KB Output is correct
55 Correct 595 ms 2904 KB Output is correct
56 Correct 535 ms 2904 KB Output is correct
57 Correct 559 ms 2904 KB Output is correct
58 Correct 556 ms 3416 KB Output is correct
59 Correct 637 ms 3692 KB Output is correct
60 Correct 652 ms 3688 KB Output is correct
61 Correct 553 ms 3160 KB Output is correct
62 Correct 526 ms 2904 KB Output is correct
63 Correct 561 ms 2904 KB Output is correct
64 Correct 559 ms 2900 KB Output is correct
65 Correct 307 ms 856 KB Output is correct
66 Correct 548 ms 3160 KB Output is correct
67 Correct 592 ms 3160 KB Output is correct
68 Correct 605 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 496 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 496 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 600 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 5 ms 600 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 373 ms 7544 KB Output is correct
44 Correct 542 ms 14964 KB Output is correct
45 Correct 585 ms 15000 KB Output is correct
46 Correct 587 ms 14572 KB Output is correct
47 Correct 454 ms 7676 KB Output is correct
48 Correct 637 ms 14568 KB Output is correct
49 Correct 636 ms 14572 KB Output is correct
50 Correct 549 ms 13400 KB Output is correct
51 Correct 273 ms 856 KB Output is correct
52 Correct 527 ms 3160 KB Output is correct
53 Correct 513 ms 3160 KB Output is correct
54 Correct 529 ms 3160 KB Output is correct
55 Correct 613 ms 21772 KB Output is correct
56 Correct 683 ms 21992 KB Output is correct
57 Correct 654 ms 22272 KB Output is correct
58 Correct 501 ms 20048 KB Output is correct
59 Correct 603 ms 28640 KB Output is correct
60 Correct 558 ms 26200 KB Output is correct
61 Correct 410 ms 2904 KB Output is correct
62 Correct 548 ms 2904 KB Output is correct
63 Correct 542 ms 2904 KB Output is correct
64 Correct 478 ms 3160 KB Output is correct
65 Correct 527 ms 3160 KB Output is correct
66 Correct 548 ms 3160 KB Output is correct
67 Correct 562 ms 3160 KB Output is correct
68 Correct 553 ms 3160 KB Output is correct
69 Correct 642 ms 2968 KB Output is correct
70 Correct 652 ms 2964 KB Output is correct
71 Correct 486 ms 1120 KB Output is correct
72 Correct 566 ms 3160 KB Output is correct
73 Correct 595 ms 2904 KB Output is correct
74 Correct 535 ms 2904 KB Output is correct
75 Correct 559 ms 2904 KB Output is correct
76 Correct 556 ms 3416 KB Output is correct
77 Correct 637 ms 3692 KB Output is correct
78 Correct 652 ms 3688 KB Output is correct
79 Correct 553 ms 3160 KB Output is correct
80 Correct 526 ms 2904 KB Output is correct
81 Correct 561 ms 2904 KB Output is correct
82 Correct 559 ms 2900 KB Output is correct
83 Correct 307 ms 856 KB Output is correct
84 Correct 548 ms 3160 KB Output is correct
85 Correct 592 ms 3160 KB Output is correct
86 Correct 605 ms 3160 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 330 ms 20852 KB Output is correct
89 Correct 584 ms 14776 KB Output is correct
90 Correct 631 ms 14740 KB Output is correct
91 Correct 602 ms 22452 KB Output is correct
92 Correct 624 ms 22508 KB Output is correct
93 Correct 627 ms 22352 KB Output is correct
94 Correct 653 ms 22704 KB Output is correct
95 Correct 578 ms 20048 KB Output is correct
96 Execution timed out 3097 ms 6352 KB Time limit exceeded
97 Halted 0 ms 0 KB -