답안 #825590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825590 2023-08-15T05:25:37 Z PoonYaPat 디지털 회로 (IOI22_circuit) C++17
100 / 100
871 ms 35068 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m,state[200005];
const ll mod=1e9+2022;
ll base[200005],sbt[200005];
vector<int> adj[200005];

void dfs1(int x) {
  sbt[x]=adj[x].size();
  for (auto s : adj[x]) {
    if (s>=n) {
      sbt[s]=1;
      continue;
    }
    dfs1(s);
    sbt[x]=(sbt[x]*sbt[s])%mod;
  }
}

void dfs2(int x, ll val) {
  if (x>=n) {
    base[x-n]=val;
    return;
  }

  int k=adj[x].size();
  ll pref[k+2],suff[k+2];
  pref[0]=1;
  suff[k]=1;

  for (int i=0; i<k; ++i) pref[i+1]=(pref[i]*sbt[adj[x][i]])%mod;
  for (int i=k-1; i>=0; --i) suff[i]=(suff[i+1]*sbt[adj[x][i]])%mod;

  for (int i=0; i<k; ++i) dfs2(adj[x][i],(((pref[i]*suff[i+1])%mod)*val)%mod);
}

ll s[1<<18],sum[1<<18];
bool lz[1<<18];

void build(int l, int r, int idx) {
  if (l==r) {
    sum[idx]=base[l];
    if (state[l]) s[idx]=base[l];
  } else {
    int mid=(l+r)/2;
    build(l,mid,2*idx);
    build(mid+1,r,2*idx+1);
    s[idx]=(s[2*idx]+s[2*idx+1])%mod;
    sum[idx]=(sum[2*idx]+sum[2*idx+1])%mod;
  }
}

void push(int l, int r, int idx) {
  if (lz[idx]) {
    s[idx]=(sum[idx]-s[idx]+mod)%mod;
    if (l!=r) {
      lz[2*idx]=!lz[2*idx];
      lz[2*idx+1]=!lz[2*idx+1];
    }
    lz[idx]=false;
  }
}

void update(int l, int r, int idx, int x, int y) {
  push(l,r,idx);
  if (x>r || y<l) return;
  if (x<=l && r<=y) {
    lz[idx]=true;
    push(l,r,idx);
  } else {
    int mid=(l+r)/2;
    update(l,mid,2*idx,x,y);
    update(mid+1,r,2*idx+1,x,y);
    s[idx]=(s[2*idx]+s[2*idx+1])%mod;
  }
}

void init(int N, int M, vector<int> P, vector<int> A) {
  n=N; m=M;
  for (int i=0; i<m; ++i) state[i]=A[i];
  for (int i=1; i<n+m; ++i) adj[P[i]].push_back(i);
  dfs1(0);
  dfs2(0,1);
  build(0,m-1,1);
}

int count_ways(int L, int R) {
  update(0,m-1,1,L-n,R-n);
  return s[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 2 ms 5072 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 2 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 2 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 625 ms 8720 KB Output is correct
2 Correct 719 ms 12424 KB Output is correct
3 Correct 811 ms 12424 KB Output is correct
4 Correct 677 ms 11916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 625 ms 8720 KB Output is correct
2 Correct 719 ms 12424 KB Output is correct
3 Correct 811 ms 12424 KB Output is correct
4 Correct 677 ms 11916 KB Output is correct
5 Correct 529 ms 8696 KB Output is correct
6 Correct 685 ms 12552 KB Output is correct
7 Correct 632 ms 12424 KB Output is correct
8 Correct 688 ms 12412 KB Output is correct
9 Correct 414 ms 5324 KB Output is correct
10 Correct 871 ms 5456 KB Output is correct
11 Correct 767 ms 5456 KB Output is correct
12 Correct 721 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 625 ms 8720 KB Output is correct
14 Correct 719 ms 12424 KB Output is correct
15 Correct 811 ms 12424 KB Output is correct
16 Correct 677 ms 11916 KB Output is correct
17 Correct 529 ms 8696 KB Output is correct
18 Correct 685 ms 12552 KB Output is correct
19 Correct 632 ms 12424 KB Output is correct
20 Correct 688 ms 12412 KB Output is correct
21 Correct 414 ms 5324 KB Output is correct
22 Correct 871 ms 5456 KB Output is correct
23 Correct 767 ms 5456 KB Output is correct
24 Correct 721 ms 5456 KB Output is correct
25 Correct 798 ms 17164 KB Output is correct
26 Correct 796 ms 17316 KB Output is correct
27 Correct 695 ms 17316 KB Output is correct
28 Correct 596 ms 17400 KB Output is correct
29 Correct 746 ms 32892 KB Output is correct
30 Correct 666 ms 32904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 2 ms 5072 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 2 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 2 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 478 ms 5292 KB Output is correct
44 Correct 470 ms 5456 KB Output is correct
45 Correct 621 ms 5384 KB Output is correct
46 Correct 544 ms 5652 KB Output is correct
47 Correct 527 ms 5712 KB Output is correct
48 Correct 622 ms 5648 KB Output is correct
49 Correct 538 ms 5712 KB Output is correct
50 Correct 636 ms 5712 KB Output is correct
51 Correct 518 ms 5520 KB Output is correct
52 Correct 668 ms 5584 KB Output is correct
53 Correct 560 ms 5968 KB Output is correct
54 Correct 617 ms 5648 KB Output is correct
55 Correct 560 ms 5584 KB Output is correct
56 Correct 636 ms 5516 KB Output is correct
57 Correct 582 ms 5520 KB Output is correct
58 Correct 634 ms 6412 KB Output is correct
59 Correct 542 ms 6616 KB Output is correct
60 Correct 450 ms 6608 KB Output is correct
61 Correct 579 ms 5516 KB Output is correct
62 Correct 575 ms 5392 KB Output is correct
63 Correct 616 ms 5376 KB Output is correct
64 Correct 649 ms 5456 KB Output is correct
65 Correct 321 ms 5200 KB Output is correct
66 Correct 595 ms 5392 KB Output is correct
67 Correct 574 ms 5456 KB Output is correct
68 Correct 632 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 2 ms 5072 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 2 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 2 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 625 ms 8720 KB Output is correct
44 Correct 719 ms 12424 KB Output is correct
45 Correct 811 ms 12424 KB Output is correct
46 Correct 677 ms 11916 KB Output is correct
47 Correct 529 ms 8696 KB Output is correct
48 Correct 685 ms 12552 KB Output is correct
49 Correct 632 ms 12424 KB Output is correct
50 Correct 688 ms 12412 KB Output is correct
51 Correct 414 ms 5324 KB Output is correct
52 Correct 871 ms 5456 KB Output is correct
53 Correct 767 ms 5456 KB Output is correct
54 Correct 721 ms 5456 KB Output is correct
55 Correct 798 ms 17164 KB Output is correct
56 Correct 796 ms 17316 KB Output is correct
57 Correct 695 ms 17316 KB Output is correct
58 Correct 596 ms 17400 KB Output is correct
59 Correct 746 ms 32892 KB Output is correct
60 Correct 666 ms 32904 KB Output is correct
61 Correct 478 ms 5292 KB Output is correct
62 Correct 470 ms 5456 KB Output is correct
63 Correct 621 ms 5384 KB Output is correct
64 Correct 544 ms 5652 KB Output is correct
65 Correct 527 ms 5712 KB Output is correct
66 Correct 622 ms 5648 KB Output is correct
67 Correct 538 ms 5712 KB Output is correct
68 Correct 636 ms 5712 KB Output is correct
69 Correct 518 ms 5520 KB Output is correct
70 Correct 668 ms 5584 KB Output is correct
71 Correct 560 ms 5968 KB Output is correct
72 Correct 617 ms 5648 KB Output is correct
73 Correct 560 ms 5584 KB Output is correct
74 Correct 636 ms 5516 KB Output is correct
75 Correct 582 ms 5520 KB Output is correct
76 Correct 634 ms 6412 KB Output is correct
77 Correct 542 ms 6616 KB Output is correct
78 Correct 450 ms 6608 KB Output is correct
79 Correct 579 ms 5516 KB Output is correct
80 Correct 575 ms 5392 KB Output is correct
81 Correct 616 ms 5376 KB Output is correct
82 Correct 649 ms 5456 KB Output is correct
83 Correct 321 ms 5200 KB Output is correct
84 Correct 595 ms 5392 KB Output is correct
85 Correct 574 ms 5456 KB Output is correct
86 Correct 632 ms 5456 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 439 ms 16380 KB Output is correct
89 Correct 580 ms 12548 KB Output is correct
90 Correct 553 ms 12244 KB Output is correct
91 Correct 528 ms 17444 KB Output is correct
92 Correct 654 ms 17520 KB Output is correct
93 Correct 682 ms 16536 KB Output is correct
94 Correct 621 ms 17412 KB Output is correct
95 Correct 614 ms 17400 KB Output is correct
96 Correct 565 ms 14720 KB Output is correct
97 Correct 514 ms 14656 KB Output is correct
98 Correct 544 ms 25352 KB Output is correct
99 Correct 735 ms 17256 KB Output is correct
100 Correct 696 ms 14940 KB Output is correct
101 Correct 753 ms 14280 KB Output is correct
102 Correct 665 ms 13128 KB Output is correct
103 Correct 690 ms 32904 KB Output is correct
104 Correct 705 ms 35068 KB Output is correct
105 Correct 681 ms 34956 KB Output is correct
106 Correct 697 ms 15620 KB Output is correct
107 Correct 635 ms 13268 KB Output is correct
108 Correct 672 ms 13320 KB Output is correct
109 Correct 767 ms 13188 KB Output is correct