답안 #1058416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058416 2024-08-14T09:54:39 Z Huseyn123 디지털 회로 (IOI22_circuit) C++17
100 / 100
744 ms 35812 KB
#include <bits/stdc++.h> 
#include "circuit.h"
#define MAX 200001
using namespace std; 
typedef long long ll;
int n,m; 
const int mod=1000002022;
vector<vector<int>> g;
long long dp[MAX],dp1[MAX];
void dfs(int v){
  if(v>=n){
    dp[v]=1; 
    return;
  }
  dp[v]=(int)g[v].size();
  for(auto x:g[v]){
    dfs(x);
    dp[v]*=dp[x];
    dp[v]%=mod;
  }
}
void dfs1(int v){
  if(v>=n){
    return; 
  }
  int sz=(int)g[v].size(); 
  vector<ll> pref(sz),suf(sz);
  for(int i=0;i<sz;i++){
    pref[i]=dp[g[v][i]];
    if(i){
      pref[i]*=pref[i-1];
      pref[i]%=mod;
    }
  }
  for(int i=sz-1;i>=0;i--){
    suf[i]=dp[g[v][i]];
    if(i!=sz-1){
      suf[i]*=suf[i+1];
      suf[i]%=mod;
    }
  }
  for(int i=0;i<sz;i++){
    int pr,sf; 
    pr=sf=1;
    if(i){
      pr=pref[i-1];
    }
    if(i!=sz-1){
      sf=suf[i+1];
    }
    dp1[g[v][i]]=dp1[v];
    dp1[g[v][i]]*=pr;
    dp1[g[v][i]]%=mod; 
    dp1[g[v][i]]*=sf;
    dp1[g[v][i]]%=mod; 
    dfs1(g[v][i]);
  }
}
ll sm(ll x,ll y){
  ll res=(x+y)%mod; 
  if(res<0){
    res+=mod;
  }
  return res;
}
ll ml(ll x,ll y){
  ll res=(x*y)%mod; 
  if(res<0){
    res+=mod;
  }
  return res; 
}
struct segtree{
    vector<ll> sums;
    vector<ll> lazy;
    int size;
    void init(int n){
        size=1;
        while(size<n){
            size*=2;
        }
        sums.assign(2*size,0LL);
        lazy.assign(2*size,1LL);
    }
    void build(int x,int lx,int rx,vector<int> &a){
        if(rx-lx==1){
            if(lx<(int)a.size()){
                sums[x]=a[lx];
            }
            return;
        }
        int m=(lx+rx)/2;
        build(2*x+1,lx,m,a);
        build(2*x+2,m,rx,a);
        sums[x]=sm(sums[2*x+1],sums[2*x+2]);
    }
    void build(vector<int> &a){
        build(0,0,size,a);
    }
    void propogate(int x,int lx,int rx){
        if(rx-lx==1){
            return;
        }
        sums[2*x+1]=ml(sums[2*x+1],lazy[x]);
        sums[2*x+2]=ml(sums[2*x+2],lazy[x]);
        lazy[2*x+1]=ml(lazy[2*x+1],lazy[x]);
        lazy[2*x+2]=ml(lazy[2*x+2],lazy[x]);
        lazy[x]=1;
    }
    void upd(int x,int lx,int rx,int l,int r,int v){
        propogate(x,lx,rx);
        if(rx<=l || lx>=r){
            return;
        }
        if(lx>=l && rx<=r){
            sums[x]=ml(sums[x],v);
            lazy[x]=ml(lazy[x],v);
            return;
        }
        int m=(lx+rx)/2;
        upd(2*x+1,lx,m,l,r,v);
        upd(2*x+2,m,rx,l,r,v);
        sums[x]=sm(sums[2*x+1],sums[2*x+2]);
    }
    void upd(int l,int r,int v){
        return upd(0,0,size,l,r,v);
    }
    ll get(int x,int lx,int rx,int l,int r){
        propogate(x,lx,rx);
        if(rx<=l || lx>=r){
            return 0;
        }
        if(lx>=l && rx<=r){
            return sums[x];
        }
        int m=(lx+rx)/2;
        ll s1,s2;
        s1=get(2*x+1,lx,m,l,r);
        s2=get(2*x+2,m,rx,l,r);
        return sm(s1,s2);
    }
    ll get(int l,int r){
        return get(0,0,size,l,r);
    }
};
segtree st;
ll res=0;
void init(int N, int M, vector<int> P, vector<int> A) {
  n=N; 
  m=M; 
  g.resize(n+m);
  for(int i=1;i<n+m;i++){
    g[P[i]].push_back(i);
  }
  dfs(0);
  dp1[0]=1;
  dfs1(0);
  st.init(m);
  vector<int> b;
  for(int i=0;i<m;i++){
    if(A[i]){
      res=sm(res,dp1[n+i]);
      b.push_back(-dp1[n+i]);
    }
    else{
      b.push_back(dp1[n+i]);
    }
  }
  st.build(b);
}
int count_ways(int L, int R) {
  res=sm(res,st.get(L-n,R-n+1));
  st.upd(L-n,R-n+1,-1);
  return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2552 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 0 ms 2392 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 0 ms 2392 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 408 ms 7240 KB Output is correct
2 Correct 595 ms 12120 KB Output is correct
3 Correct 548 ms 12084 KB Output is correct
4 Correct 577 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 408 ms 7240 KB Output is correct
2 Correct 595 ms 12120 KB Output is correct
3 Correct 548 ms 12084 KB Output is correct
4 Correct 577 ms 12120 KB Output is correct
5 Correct 550 ms 7256 KB Output is correct
6 Correct 679 ms 12048 KB Output is correct
7 Correct 700 ms 12120 KB Output is correct
8 Correct 690 ms 12100 KB Output is correct
9 Correct 306 ms 2644 KB Output is correct
10 Correct 643 ms 2904 KB Output is correct
11 Correct 608 ms 2904 KB Output is correct
12 Correct 597 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 408 ms 7240 KB Output is correct
14 Correct 595 ms 12120 KB Output is correct
15 Correct 548 ms 12084 KB Output is correct
16 Correct 577 ms 12120 KB Output is correct
17 Correct 550 ms 7256 KB Output is correct
18 Correct 679 ms 12048 KB Output is correct
19 Correct 700 ms 12120 KB Output is correct
20 Correct 690 ms 12100 KB Output is correct
21 Correct 306 ms 2644 KB Output is correct
22 Correct 643 ms 2904 KB Output is correct
23 Correct 608 ms 2904 KB Output is correct
24 Correct 597 ms 2904 KB Output is correct
25 Correct 664 ms 18124 KB Output is correct
26 Correct 705 ms 18384 KB Output is correct
27 Correct 688 ms 18392 KB Output is correct
28 Correct 580 ms 18380 KB Output is correct
29 Correct 720 ms 33876 KB Output is correct
30 Correct 700 ms 33872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2552 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 0 ms 2392 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 0 ms 2392 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 430 ms 2904 KB Output is correct
44 Correct 605 ms 2904 KB Output is correct
45 Correct 604 ms 2904 KB Output is correct
46 Correct 589 ms 3416 KB Output is correct
47 Correct 588 ms 3416 KB Output is correct
48 Correct 622 ms 3416 KB Output is correct
49 Correct 629 ms 3388 KB Output is correct
50 Correct 638 ms 3412 KB Output is correct
51 Correct 609 ms 2904 KB Output is correct
52 Correct 602 ms 2904 KB Output is correct
53 Correct 497 ms 3672 KB Output is correct
54 Correct 618 ms 3416 KB Output is correct
55 Correct 574 ms 3216 KB Output is correct
56 Correct 575 ms 3160 KB Output is correct
57 Correct 537 ms 3056 KB Output is correct
58 Correct 561 ms 3928 KB Output is correct
59 Correct 500 ms 4184 KB Output is correct
60 Correct 528 ms 4184 KB Output is correct
61 Correct 653 ms 3192 KB Output is correct
62 Correct 573 ms 3156 KB Output is correct
63 Correct 604 ms 2904 KB Output is correct
64 Correct 546 ms 3112 KB Output is correct
65 Correct 296 ms 2644 KB Output is correct
66 Correct 592 ms 2904 KB Output is correct
67 Correct 598 ms 2904 KB Output is correct
68 Correct 539 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 1 ms 2552 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 0 ms 2392 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 0 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 0 ms 2392 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 0 ms 2392 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 408 ms 7240 KB Output is correct
44 Correct 595 ms 12120 KB Output is correct
45 Correct 548 ms 12084 KB Output is correct
46 Correct 577 ms 12120 KB Output is correct
47 Correct 550 ms 7256 KB Output is correct
48 Correct 679 ms 12048 KB Output is correct
49 Correct 700 ms 12120 KB Output is correct
50 Correct 690 ms 12100 KB Output is correct
51 Correct 306 ms 2644 KB Output is correct
52 Correct 643 ms 2904 KB Output is correct
53 Correct 608 ms 2904 KB Output is correct
54 Correct 597 ms 2904 KB Output is correct
55 Correct 664 ms 18124 KB Output is correct
56 Correct 705 ms 18384 KB Output is correct
57 Correct 688 ms 18392 KB Output is correct
58 Correct 580 ms 18380 KB Output is correct
59 Correct 720 ms 33876 KB Output is correct
60 Correct 700 ms 33872 KB Output is correct
61 Correct 430 ms 2904 KB Output is correct
62 Correct 605 ms 2904 KB Output is correct
63 Correct 604 ms 2904 KB Output is correct
64 Correct 589 ms 3416 KB Output is correct
65 Correct 588 ms 3416 KB Output is correct
66 Correct 622 ms 3416 KB Output is correct
67 Correct 629 ms 3388 KB Output is correct
68 Correct 638 ms 3412 KB Output is correct
69 Correct 609 ms 2904 KB Output is correct
70 Correct 602 ms 2904 KB Output is correct
71 Correct 497 ms 3672 KB Output is correct
72 Correct 618 ms 3416 KB Output is correct
73 Correct 574 ms 3216 KB Output is correct
74 Correct 575 ms 3160 KB Output is correct
75 Correct 537 ms 3056 KB Output is correct
76 Correct 561 ms 3928 KB Output is correct
77 Correct 500 ms 4184 KB Output is correct
78 Correct 528 ms 4184 KB Output is correct
79 Correct 653 ms 3192 KB Output is correct
80 Correct 573 ms 3156 KB Output is correct
81 Correct 604 ms 2904 KB Output is correct
82 Correct 546 ms 3112 KB Output is correct
83 Correct 296 ms 2644 KB Output is correct
84 Correct 592 ms 2904 KB Output is correct
85 Correct 598 ms 2904 KB Output is correct
86 Correct 539 ms 2904 KB Output is correct
87 Correct 0 ms 2392 KB Output is correct
88 Correct 397 ms 17248 KB Output is correct
89 Correct 618 ms 12120 KB Output is correct
90 Correct 692 ms 11772 KB Output is correct
91 Correct 623 ms 18404 KB Output is correct
92 Correct 708 ms 18384 KB Output is correct
93 Correct 673 ms 18596 KB Output is correct
94 Correct 721 ms 18396 KB Output is correct
95 Correct 659 ms 18448 KB Output is correct
96 Correct 622 ms 12080 KB Output is correct
97 Correct 732 ms 11952 KB Output is correct
98 Correct 492 ms 29340 KB Output is correct
99 Correct 699 ms 18384 KB Output is correct
100 Correct 704 ms 14856 KB Output is correct
101 Correct 744 ms 13476 KB Output is correct
102 Correct 696 ms 11740 KB Output is correct
103 Correct 690 ms 34112 KB Output is correct
104 Correct 709 ms 35812 KB Output is correct
105 Correct 649 ms 35792 KB Output is correct
106 Correct 699 ms 15696 KB Output is correct
107 Correct 675 ms 12748 KB Output is correct
108 Correct 674 ms 12504 KB Output is correct
109 Correct 676 ms 11988 KB Output is correct