답안 #1061226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061226 2024-08-16T07:23:12 Z epicci23 디지털 회로 (IOI22_circuit) C++17
100 / 100
769 ms 42200 KB
#include "bits/stdc++.h"
#include "circuit.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int64_t) a.size()
using namespace std;

const int64_t MOD = 1000002022;

int64_t add(int64_t a,int64_t b){
  if(a+b>=MOD) return a+b-MOD;
  return a+b;
}

int64_t mult(int64_t a,int64_t b){
 if((a*b)>=MOD) return (a*b)%MOD;
 return a*b;
}

const int N = 2e5 + 5;
vector<int> v[N];
int64_t sub[N],n,m;
vector<int64_t> ans,col;

struct SegT{
  vector<array<int64_t,2>> v;
  vector<int> lazy;
  void init(int n){
  	lazy.resize(4*n+5,0);
    v.resize(4*n+5);
  }
  array<int64_t,2> merge(array<int64_t,2> a,array<int64_t,2> b){
  	array<int64_t,2> res;
  	res[0]=add(a[0],b[0]);
  	res[1]=add(a[1],b[1]);
  	return res;
  }
  void build(int rt,int l,int r){
  	if(l==r){
  	  v[rt][0]=mult(col[l],ans[l]);
  	  v[rt][1]=mult(1-col[l],ans[l]);
      //cout << n+l << ' ' <<  col[l] << ' ' << v[rt][0] << ' ' << v[rt][1] << '\n'; 
  	  return;
  	}
  	int m=(l+r)/2;
  	build(rt*2,l,m),build(rt*2+1,m+1,r);
  	v[rt]=merge(v[rt*2],v[rt*2+1]);
  }
  void push(int rt,int l,int r){
    if(!lazy[rt]) return;
    swap(v[rt][0],v[rt][1]);
    lazy[rt]=0;
    if(l==r) return;
    lazy[rt*2]^=1;
    lazy[rt*2+1]^=1;
  }
  void upd(int rt,int l,int r,int gl,int gr){
  	push(rt,l,r);
    if(r<gl || l>gr) return;
    if(l>=gl && r<=gr){
      lazy[rt]^=1;
      push(rt,l,r);
      return;
    }
    int m=(l+r)/2;
    upd(rt*2,l,m,gl,gr),upd(rt*2+1,m+1,r,gl,gr);
    v[rt]=merge(v[rt*2],v[rt*2+1]);
  }
};

SegT seg;

void dfs(int c){
  int64_t res=1;
  for(int x:v[c]){
   dfs(x);
   res=mult(res,sub[x]);
  }
  if(sz(v[c])>0) res=mult(res,sz(v[c]));
  sub[c]=res;
}

void dfs2(int c,int64_t val){
  if(sz(v[c])==0){
    ans[c-n]=val;
    return;
  }
  vector<int64_t> pre(sz(v[c])),suf(sz(v[c]));
  int64_t cur=1;
  for(int i=0;i<sz(v[c]);i++){
    cur=mult(cur,sub[v[c][i]]);
    pre[i]=cur;
  }
  cur=1;
  for(int i=sz(v[c])-1;i>=0;i--){
  	cur=mult(cur,sub[v[c][i]]);
  	suf[i]=cur;
  }
  for(int i=0;i<sz(v[c]);i++)
  	dfs2(v[c][i],mult((i+1<sz(v[c])?suf[i+1]:1),mult(val,(i>0 ? pre[i-1] : 1))));
}

void init(int N, int M, vector<int> P, vector<int> A){
  n=N,m=M;
  ans.resize(m),col.resize(m);
  for(int i=1;i<n+m;i++) v[P[i]].push_back(i);
  for(int i=0;i<m;i++) col[i]=A[i];
  dfs(0),dfs2(0,1);
  seg.init(m);
  seg.build(1,0,m-1);
}

int count_ways(int L, int R){
  L-=n,R-=n;
  seg.upd(1,0,m-1,L,R);
  return (int32_t)seg.v[1][0];
}

/*void _(){
  cin >> n >> m;
  ans.resize(m),col.resize(m);
  for(int i=0;i<n+m;i++){
  	int a;cin >> a;
  	if(a>=0) v[a].push_back(i);
  }
  for(int i=0;i<m;i++) cin >> col[i];
  dfs(0),dfs2(0,1);
  SegT seg(m);
  seg.build(1,0,m-1);
  int q;cin >> q;
  while(q--){
  	int l,r;
  	cin >> l >> r;
    l-=n;r-=n;
  	seg.upd(1,0,m-1,l,r);
  	cout << seg.v[1][0] << '\n';
  }
}

int32_t main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
  return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6468 KB Output is correct
4 Correct 2 ms 6584 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 3 ms 6648 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 3 ms 6488 KB Output is correct
10 Correct 3 ms 6744 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6468 KB Output is correct
12 Correct 2 ms 6584 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 3 ms 6648 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 3 ms 6488 KB Output is correct
18 Correct 3 ms 6744 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6580 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 2 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6536 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 2 ms 6632 KB Output is correct
36 Correct 2 ms 6744 KB Output is correct
37 Correct 3 ms 6792 KB Output is correct
38 Correct 2 ms 6744 KB Output is correct
39 Correct 3 ms 6488 KB Output is correct
40 Correct 3 ms 6500 KB Output is correct
41 Correct 2 ms 6584 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 11524 KB Output is correct
2 Correct 552 ms 16208 KB Output is correct
3 Correct 576 ms 16272 KB Output is correct
4 Correct 694 ms 16264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 11524 KB Output is correct
2 Correct 552 ms 16208 KB Output is correct
3 Correct 576 ms 16272 KB Output is correct
4 Correct 694 ms 16264 KB Output is correct
5 Correct 481 ms 11340 KB Output is correct
6 Correct 634 ms 16472 KB Output is correct
7 Correct 693 ms 16472 KB Output is correct
8 Correct 678 ms 16472 KB Output is correct
9 Correct 256 ms 6744 KB Output is correct
10 Correct 635 ms 7200 KB Output is correct
11 Correct 605 ms 7196 KB Output is correct
12 Correct 681 ms 7192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6468 KB Output is correct
4 Correct 2 ms 6584 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 3 ms 6648 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 3 ms 6488 KB Output is correct
10 Correct 3 ms 6744 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 411 ms 11524 KB Output is correct
14 Correct 552 ms 16208 KB Output is correct
15 Correct 576 ms 16272 KB Output is correct
16 Correct 694 ms 16264 KB Output is correct
17 Correct 481 ms 11340 KB Output is correct
18 Correct 634 ms 16472 KB Output is correct
19 Correct 693 ms 16472 KB Output is correct
20 Correct 678 ms 16472 KB Output is correct
21 Correct 256 ms 6744 KB Output is correct
22 Correct 635 ms 7200 KB Output is correct
23 Correct 605 ms 7196 KB Output is correct
24 Correct 681 ms 7192 KB Output is correct
25 Correct 687 ms 21256 KB Output is correct
26 Correct 683 ms 21524 KB Output is correct
27 Correct 753 ms 21428 KB Output is correct
28 Correct 637 ms 21332 KB Output is correct
29 Correct 670 ms 41808 KB Output is correct
30 Correct 576 ms 41740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6468 KB Output is correct
12 Correct 2 ms 6584 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 3 ms 6648 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 3 ms 6488 KB Output is correct
18 Correct 3 ms 6744 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6580 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 2 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6536 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 2 ms 6632 KB Output is correct
36 Correct 2 ms 6744 KB Output is correct
37 Correct 3 ms 6792 KB Output is correct
38 Correct 2 ms 6744 KB Output is correct
39 Correct 3 ms 6488 KB Output is correct
40 Correct 3 ms 6500 KB Output is correct
41 Correct 2 ms 6584 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
43 Correct 371 ms 7000 KB Output is correct
44 Correct 571 ms 7000 KB Output is correct
45 Correct 687 ms 7000 KB Output is correct
46 Correct 520 ms 7256 KB Output is correct
47 Correct 612 ms 7352 KB Output is correct
48 Correct 588 ms 7256 KB Output is correct
49 Correct 650 ms 7256 KB Output is correct
50 Correct 585 ms 7256 KB Output is correct
51 Correct 619 ms 6992 KB Output is correct
52 Correct 598 ms 7000 KB Output is correct
53 Correct 577 ms 7768 KB Output is correct
54 Correct 610 ms 7256 KB Output is correct
55 Correct 630 ms 7224 KB Output is correct
56 Correct 702 ms 7000 KB Output is correct
57 Correct 621 ms 7124 KB Output is correct
58 Correct 656 ms 8280 KB Output is correct
59 Correct 552 ms 8280 KB Output is correct
60 Correct 629 ms 8280 KB Output is correct
61 Correct 725 ms 7000 KB Output is correct
62 Correct 630 ms 7036 KB Output is correct
63 Correct 656 ms 7032 KB Output is correct
64 Correct 666 ms 7000 KB Output is correct
65 Correct 367 ms 6744 KB Output is correct
66 Correct 677 ms 7200 KB Output is correct
67 Correct 668 ms 7200 KB Output is correct
68 Correct 650 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6468 KB Output is correct
12 Correct 2 ms 6584 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 3 ms 6648 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 3 ms 6488 KB Output is correct
18 Correct 3 ms 6744 KB Output is correct
19 Correct 2 ms 6744 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6580 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 2 ms 6488 KB Output is correct
27 Correct 3 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6536 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 2 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 2 ms 6632 KB Output is correct
36 Correct 2 ms 6744 KB Output is correct
37 Correct 3 ms 6792 KB Output is correct
38 Correct 2 ms 6744 KB Output is correct
39 Correct 3 ms 6488 KB Output is correct
40 Correct 3 ms 6500 KB Output is correct
41 Correct 2 ms 6584 KB Output is correct
42 Correct 2 ms 6488 KB Output is correct
43 Correct 411 ms 11524 KB Output is correct
44 Correct 552 ms 16208 KB Output is correct
45 Correct 576 ms 16272 KB Output is correct
46 Correct 694 ms 16264 KB Output is correct
47 Correct 481 ms 11340 KB Output is correct
48 Correct 634 ms 16472 KB Output is correct
49 Correct 693 ms 16472 KB Output is correct
50 Correct 678 ms 16472 KB Output is correct
51 Correct 256 ms 6744 KB Output is correct
52 Correct 635 ms 7200 KB Output is correct
53 Correct 605 ms 7196 KB Output is correct
54 Correct 681 ms 7192 KB Output is correct
55 Correct 687 ms 21256 KB Output is correct
56 Correct 683 ms 21524 KB Output is correct
57 Correct 753 ms 21428 KB Output is correct
58 Correct 637 ms 21332 KB Output is correct
59 Correct 670 ms 41808 KB Output is correct
60 Correct 576 ms 41740 KB Output is correct
61 Correct 371 ms 7000 KB Output is correct
62 Correct 571 ms 7000 KB Output is correct
63 Correct 687 ms 7000 KB Output is correct
64 Correct 520 ms 7256 KB Output is correct
65 Correct 612 ms 7352 KB Output is correct
66 Correct 588 ms 7256 KB Output is correct
67 Correct 650 ms 7256 KB Output is correct
68 Correct 585 ms 7256 KB Output is correct
69 Correct 619 ms 6992 KB Output is correct
70 Correct 598 ms 7000 KB Output is correct
71 Correct 577 ms 7768 KB Output is correct
72 Correct 610 ms 7256 KB Output is correct
73 Correct 630 ms 7224 KB Output is correct
74 Correct 702 ms 7000 KB Output is correct
75 Correct 621 ms 7124 KB Output is correct
76 Correct 656 ms 8280 KB Output is correct
77 Correct 552 ms 8280 KB Output is correct
78 Correct 629 ms 8280 KB Output is correct
79 Correct 725 ms 7000 KB Output is correct
80 Correct 630 ms 7036 KB Output is correct
81 Correct 656 ms 7032 KB Output is correct
82 Correct 666 ms 7000 KB Output is correct
83 Correct 367 ms 6744 KB Output is correct
84 Correct 677 ms 7200 KB Output is correct
85 Correct 668 ms 7200 KB Output is correct
86 Correct 650 ms 7248 KB Output is correct
87 Correct 2 ms 6488 KB Output is correct
88 Correct 436 ms 19252 KB Output is correct
89 Correct 760 ms 14904 KB Output is correct
90 Correct 717 ms 15432 KB Output is correct
91 Correct 758 ms 21532 KB Output is correct
92 Correct 739 ms 21584 KB Output is correct
93 Correct 762 ms 21584 KB Output is correct
94 Correct 699 ms 21584 KB Output is correct
95 Correct 727 ms 21620 KB Output is correct
96 Correct 630 ms 18096 KB Output is correct
97 Correct 658 ms 18088 KB Output is correct
98 Correct 676 ms 32336 KB Output is correct
99 Correct 733 ms 21532 KB Output is correct
100 Correct 736 ms 19536 KB Output is correct
101 Correct 722 ms 19032 KB Output is correct
102 Correct 671 ms 18008 KB Output is correct
103 Correct 769 ms 41820 KB Output is correct
104 Correct 736 ms 42160 KB Output is correct
105 Correct 696 ms 42200 KB Output is correct
106 Correct 701 ms 19024 KB Output is correct
107 Correct 697 ms 15448 KB Output is correct
108 Correct 718 ms 16228 KB Output is correct
109 Correct 727 ms 18264 KB Output is correct