답안 #697354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697354 2023-02-09T12:26:06 Z FEDIKUS 디지털 회로 (IOI22_circuit) C++17
100 / 100
1064 ms 35588 KB
#include "circuit.h"

#include<bits/stdc++.h>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn=2e5+10;
const int mod=1e9+2022;

int n,m;

vector<int> g[maxn];
vector<int> p,a;

int add(int a,int b){
  return (a+b)%mod;
}

int mul(int a,int b){
  return ll(a)*ll(b)%mod;
}

int bruk[maxn];
int power[maxn];

void dfs(int node){
  bruk[node]=1;
  if(node<n) bruk[node]=mul(bruk[node],g[node].size());
  for(int i:g[node]){
    dfs(i);
    bruk[node]=mul(bruk[node],bruk[i]);
  }
}

void dfs2(int node,int tren){
  if(node>=n){
    power[node-n]=tren;
    return;
  }
  vector<int> pref(g[node].size());
  vector<int> suf(g[node].size());
  for(int i=0;i<(int)g[node].size();i++){
    if(i==0) pref[i]=bruk[g[node][i]];
    else pref[i]=mul(pref[i-1],bruk[g[node][i]]);
  }
  for(int i=(int)g[node].size()-1;i>=0;i--){
    if(i==(int)g[node].size()-1) suf[i]=bruk[g[node][i]];
    else suf[i]=mul(suf[i+1],bruk[g[node][i]]);
  }
  for(int i=0;i<(int)g[node].size();i++){
    int ntren=tren;
    if(i>0) ntren=mul(ntren,pref[i-1]);
    if(i<(int)g[node].size()-1) ntren=mul(ntren,suf[i+1]);
    dfs2(g[node][i],ntren);
  }
}

pair<int,int> segt[4*maxn];
int lazy[4*maxn];

void update(int t,int v1,int v0,int ind=1,int l=0,int r=m-1){
  if(l==r){
    segt[ind].first=v1;
    segt[ind].second=v0;
    return;
  }
  int mid=(l+r)/2;
  if(t<=mid) update(t,v1,v0,2*ind,l,mid);
  else update(t,v1,v0,2*ind+1,mid+1,r);
  segt[ind].first=add(segt[2*ind].first,segt[2*ind+1].first);
  segt[ind].second=add(segt[2*ind].second,segt[2*ind+1].second);
}

void push(int ind){
  if(!lazy[ind]) return;
  swap(segt[2*ind].first,segt[2*ind].second);
  swap(segt[2*ind+1].first,segt[2*ind+1].second);
  lazy[2*ind]^=1;
  lazy[2*ind+1]^=1;
  lazy[ind]=0;
}

void flip(int tl,int tr,int ind=1,int l=0,int r=m-1){
  if(l!=r) push(ind);
  if(tl<=l && r<=tr){
    swap(segt[ind].first,segt[ind].second);
    lazy[ind]^=1;
    return;
  }
  int mid=(l+r)/2;
  if(tl<=mid) flip(tl,tr,2*ind,l,mid);
  if(tr>mid) flip(tl,tr,2*ind+1,mid+1,r);
  segt[ind].first=add(segt[2*ind].first,segt[2*ind+1].first);
  segt[ind].second=add(segt[2*ind].second,segt[2*ind+1].second);
}

void init(int N,int M, vector<int> P, vector<int> A) {
  n=N; m=M; p=P; a=A;
  for(int i=1;i<n+m;i++) g[p[i]].push_back(i);
  dfs(0);
  dfs2(0,1);
  for(int i=0;i<m;i++){
    int v1=power[i];
    int v0=0;
    if(!a[i]) swap(v1,v0);
    update(i,v1,v0);
  }
}

int count_ways(int L, int R) {
  L-=n;
  R-=n;
  flip(L,R);
  return segt[1].first;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5088 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 4944 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 5 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 5088 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5088 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5120 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 5 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 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 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 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5128 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5268 KB Output is correct
37 Correct 4 ms 5340 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 522 ms 8080 KB Output is correct
2 Correct 848 ms 11144 KB Output is correct
3 Correct 875 ms 11156 KB Output is correct
4 Correct 773 ms 11092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 522 ms 8080 KB Output is correct
2 Correct 848 ms 11144 KB Output is correct
3 Correct 875 ms 11156 KB Output is correct
4 Correct 773 ms 11092 KB Output is correct
5 Correct 705 ms 8080 KB Output is correct
6 Correct 953 ms 11080 KB Output is correct
7 Correct 856 ms 11160 KB Output is correct
8 Correct 848 ms 11132 KB Output is correct
9 Correct 387 ms 5128 KB Output is correct
10 Correct 877 ms 5328 KB Output is correct
11 Correct 853 ms 5368 KB Output is correct
12 Correct 857 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 4944 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5120 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 5 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 522 ms 8080 KB Output is correct
14 Correct 848 ms 11144 KB Output is correct
15 Correct 875 ms 11156 KB Output is correct
16 Correct 773 ms 11092 KB Output is correct
17 Correct 705 ms 8080 KB Output is correct
18 Correct 953 ms 11080 KB Output is correct
19 Correct 856 ms 11160 KB Output is correct
20 Correct 848 ms 11132 KB Output is correct
21 Correct 387 ms 5128 KB Output is correct
22 Correct 877 ms 5328 KB Output is correct
23 Correct 853 ms 5368 KB Output is correct
24 Correct 857 ms 5328 KB Output is correct
25 Correct 886 ms 14656 KB Output is correct
26 Correct 1064 ms 15048 KB Output is correct
27 Correct 870 ms 14828 KB Output is correct
28 Correct 624 ms 14840 KB Output is correct
29 Correct 1012 ms 35272 KB Output is correct
30 Correct 978 ms 35192 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 5088 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5088 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5120 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 5 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 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 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 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5128 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5268 KB Output is correct
37 Correct 4 ms 5340 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5084 KB Output is correct
43 Correct 621 ms 5328 KB Output is correct
44 Correct 772 ms 5328 KB Output is correct
45 Correct 761 ms 5352 KB Output is correct
46 Correct 881 ms 5584 KB Output is correct
47 Correct 779 ms 5584 KB Output is correct
48 Correct 853 ms 5584 KB Output is correct
49 Correct 951 ms 5596 KB Output is correct
50 Correct 820 ms 5456 KB Output is correct
51 Correct 739 ms 5384 KB Output is correct
52 Correct 812 ms 5428 KB Output is correct
53 Correct 809 ms 6224 KB Output is correct
54 Correct 856 ms 5584 KB Output is correct
55 Correct 733 ms 5456 KB Output is correct
56 Correct 900 ms 5328 KB Output is correct
57 Correct 896 ms 5328 KB Output is correct
58 Correct 793 ms 6608 KB Output is correct
59 Correct 859 ms 6608 KB Output is correct
60 Correct 713 ms 6608 KB Output is correct
61 Correct 805 ms 5480 KB Output is correct
62 Correct 799 ms 5328 KB Output is correct
63 Correct 754 ms 5200 KB Output is correct
64 Correct 819 ms 5328 KB Output is correct
65 Correct 485 ms 5228 KB Output is correct
66 Correct 839 ms 5420 KB Output is correct
67 Correct 856 ms 5328 KB Output is correct
68 Correct 881 ms 5328 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 5088 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5088 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5120 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 5 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 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 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 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5128 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5268 KB Output is correct
37 Correct 4 ms 5340 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5084 KB Output is correct
43 Correct 522 ms 8080 KB Output is correct
44 Correct 848 ms 11144 KB Output is correct
45 Correct 875 ms 11156 KB Output is correct
46 Correct 773 ms 11092 KB Output is correct
47 Correct 705 ms 8080 KB Output is correct
48 Correct 953 ms 11080 KB Output is correct
49 Correct 856 ms 11160 KB Output is correct
50 Correct 848 ms 11132 KB Output is correct
51 Correct 387 ms 5128 KB Output is correct
52 Correct 877 ms 5328 KB Output is correct
53 Correct 853 ms 5368 KB Output is correct
54 Correct 857 ms 5328 KB Output is correct
55 Correct 886 ms 14656 KB Output is correct
56 Correct 1064 ms 15048 KB Output is correct
57 Correct 870 ms 14828 KB Output is correct
58 Correct 624 ms 14840 KB Output is correct
59 Correct 1012 ms 35272 KB Output is correct
60 Correct 978 ms 35192 KB Output is correct
61 Correct 621 ms 5328 KB Output is correct
62 Correct 772 ms 5328 KB Output is correct
63 Correct 761 ms 5352 KB Output is correct
64 Correct 881 ms 5584 KB Output is correct
65 Correct 779 ms 5584 KB Output is correct
66 Correct 853 ms 5584 KB Output is correct
67 Correct 951 ms 5596 KB Output is correct
68 Correct 820 ms 5456 KB Output is correct
69 Correct 739 ms 5384 KB Output is correct
70 Correct 812 ms 5428 KB Output is correct
71 Correct 809 ms 6224 KB Output is correct
72 Correct 856 ms 5584 KB Output is correct
73 Correct 733 ms 5456 KB Output is correct
74 Correct 900 ms 5328 KB Output is correct
75 Correct 896 ms 5328 KB Output is correct
76 Correct 793 ms 6608 KB Output is correct
77 Correct 859 ms 6608 KB Output is correct
78 Correct 713 ms 6608 KB Output is correct
79 Correct 805 ms 5480 KB Output is correct
80 Correct 799 ms 5328 KB Output is correct
81 Correct 754 ms 5200 KB Output is correct
82 Correct 819 ms 5328 KB Output is correct
83 Correct 485 ms 5228 KB Output is correct
84 Correct 839 ms 5420 KB Output is correct
85 Correct 856 ms 5328 KB Output is correct
86 Correct 881 ms 5328 KB Output is correct
87 Correct 4 ms 4944 KB Output is correct
88 Correct 615 ms 14140 KB Output is correct
89 Correct 871 ms 11268 KB Output is correct
90 Correct 867 ms 11100 KB Output is correct
91 Correct 851 ms 14988 KB Output is correct
92 Correct 993 ms 15008 KB Output is correct
93 Correct 886 ms 15080 KB Output is correct
94 Correct 1016 ms 15000 KB Output is correct
95 Correct 859 ms 14980 KB Output is correct
96 Correct 932 ms 10716 KB Output is correct
97 Correct 955 ms 11080 KB Output is correct
98 Correct 770 ms 29956 KB Output is correct
99 Correct 978 ms 14836 KB Output is correct
100 Correct 993 ms 12612 KB Output is correct
101 Correct 831 ms 12036 KB Output is correct
102 Correct 848 ms 10964 KB Output is correct
103 Correct 952 ms 35124 KB Output is correct
104 Correct 931 ms 35588 KB Output is correct
105 Correct 761 ms 35568 KB Output is correct
106 Correct 955 ms 15304 KB Output is correct
107 Correct 1006 ms 11500 KB Output is correct
108 Correct 852 ms 11336 KB Output is correct
109 Correct 879 ms 11112 KB Output is correct