답안 #856107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856107 2023-10-02T16:44:23 Z Urvuk3 디지털 회로 (IOI22_circuit) C++17
100 / 100
764 ms 51600 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

const int mxN=2e5;
const ll MOD=1000002022;

vector<ll> contribute(mxN,1),sub(mxN,1);
vector<int> lazy(4*mxN),adj[mxN];
int N,M;

void Md(ll& x){
    if(x>=MOD) x%=MOD;
    if(x<0) x+=MOD;
}

struct Node{
    ll tmp,all;
}; vector<Node> seg(4*mxN);

Node Merge(Node& n1,Node& n2){
    Node ret={n1.tmp+n2.tmp,n1.all+n2.all};
    Md(ret.tmp); Md(ret.all);
    return ret;
}

void Propagate(int node,int l,int r){
    if(lazy[node]){
        seg[node].tmp=seg[node].all-seg[node].tmp; Md(seg[node].tmp);
        if(l<=r){
            lazy[2*node]^=1;
            lazy[2*node+1]^=1;
        }
        lazy[node]=0;
    }
}

void Build(int node,int l,int r,vector<int>& A){
    if(l==r){
        seg[node].tmp=(A[l] ? contribute[l+N] : 0);
        seg[node].all=contribute[l+N];
        return;
    }
    Build(2*node,l,mid,A); Build(2*node+1,mid+1,r,A);
    seg[node]=Merge(seg[2*node],seg[2*node+1]);
}

void Update(int node,int l,int r,int L,int R){
    if(l>r) return;
    Propagate(node,l,r);
    if(L>r || R<l) return;
    if(L<=l && r<=R){
        lazy[node]=1;
        Propagate(node,l,r);
        return;
    }
    Update(2*node,l,mid,L,R); Update(2*node+1,mid+1,r,L,R);
    seg[node]=Merge(seg[2*node],seg[2*node+1]);
}

void DfsSub(int node,int par){
    int c=0;
    for(int v:adj[node]){
        if(v!=par){
            DfsSub(v,node);
            sub[node]*=sub[v]; Md(sub[node]);
            c++;
        }
    }
    if(0<=node && node<N){
        sub[node]*=c; Md(sub[node]);
    }
}

void DfsCon(int node,int par){
    if(par!=-1){
        contribute[node]*=contribute[par]; Md(contribute[node]);
    }
    vector<ll> pref(sz(adj[node]),1),suf(sz(adj[node]),1);
    for(int i=0;i<sz(adj[node]);i++){
        int v=adj[node][i];
        if(i){
            pref[i]=pref[i-1]; Md(pref[i]);
        }
        if(v!=par){
            pref[i]*=sub[v]; Md(pref[i]);
        }
    }
    for(int i=sz(adj[node])-1;i>=0;i--){
        int v=adj[node][i];
        if(i!=sz(adj[node])-1){
            suf[i]=suf[i+1]; Md(suf[i]);
        }
        if(v!=par){
            suf[i]*=sub[v]; Md(suf[i]);
        }
    }
    for(int i=0;i<sz(adj[node]);i++){
        int v=adj[node][i];
        if(v!=par){
            if(i){
                contribute[v]*=pref[i-1]; Md(contribute[v]);
            }
            if(i<sz(adj[node])-1){
                contribute[v]*=suf[i+1]; Md(contribute[v]);
            }
        }
    }
    for(int v:adj[node]){
        if(v!=par){
            DfsCon(v,node);
        }
    }
}

void init(int N1, int M1, std::vector<int> P, std::vector<int> A) {
    N=N1,M=M1;
    for(int i=1;i<N+M;i++){
        adj[P[i]].pb(i);
    }
    DfsSub(0,-1);
    DfsCon(0,-1);
    Build(1,0,M-1,A);
}

int count_ways(int L, int R) {
    Update(1,0,M-1,L-N,R-N);
    return seg[1].tmp;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23980 KB Output is correct
6 Correct 6 ms 23932 KB Output is correct
7 Correct 5 ms 23896 KB Output is correct
8 Correct 7 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 6 ms 23896 KB Output is correct
3 Correct 6 ms 23784 KB Output is correct
4 Correct 6 ms 23828 KB Output is correct
5 Correct 6 ms 23896 KB Output is correct
6 Correct 6 ms 23896 KB Output is correct
7 Correct 6 ms 23896 KB Output is correct
8 Correct 6 ms 23896 KB Output is correct
9 Correct 6 ms 23896 KB Output is correct
10 Correct 6 ms 24152 KB Output is correct
11 Correct 7 ms 24408 KB Output is correct
12 Correct 6 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23980 KB Output is correct
6 Correct 6 ms 23932 KB Output is correct
7 Correct 5 ms 23896 KB Output is correct
8 Correct 7 ms 23896 KB Output is correct
9 Correct 5 ms 23896 KB Output is correct
10 Correct 6 ms 23896 KB Output is correct
11 Correct 6 ms 23784 KB Output is correct
12 Correct 6 ms 23828 KB Output is correct
13 Correct 6 ms 23896 KB Output is correct
14 Correct 6 ms 23896 KB Output is correct
15 Correct 6 ms 23896 KB Output is correct
16 Correct 6 ms 23896 KB Output is correct
17 Correct 6 ms 23896 KB Output is correct
18 Correct 6 ms 24152 KB Output is correct
19 Correct 7 ms 24408 KB Output is correct
20 Correct 6 ms 23896 KB Output is correct
21 Correct 6 ms 23896 KB Output is correct
22 Correct 6 ms 24152 KB Output is correct
23 Correct 6 ms 23896 KB Output is correct
24 Correct 6 ms 23896 KB Output is correct
25 Correct 6 ms 24036 KB Output is correct
26 Correct 6 ms 23896 KB Output is correct
27 Correct 7 ms 23808 KB Output is correct
28 Correct 6 ms 23896 KB Output is correct
29 Correct 6 ms 23896 KB Output is correct
30 Correct 6 ms 23896 KB Output is correct
31 Correct 6 ms 24152 KB Output is correct
32 Correct 6 ms 23896 KB Output is correct
33 Correct 6 ms 23896 KB Output is correct
34 Correct 6 ms 23896 KB Output is correct
35 Correct 6 ms 23896 KB Output is correct
36 Correct 6 ms 23972 KB Output is correct
37 Correct 6 ms 24152 KB Output is correct
38 Correct 7 ms 24152 KB Output is correct
39 Correct 6 ms 24152 KB Output is correct
40 Correct 7 ms 23896 KB Output is correct
41 Correct 6 ms 23896 KB Output is correct
42 Correct 6 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 25756 KB Output is correct
2 Correct 555 ms 27520 KB Output is correct
3 Correct 580 ms 27480 KB Output is correct
4 Correct 566 ms 27532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 25756 KB Output is correct
2 Correct 555 ms 27520 KB Output is correct
3 Correct 580 ms 27480 KB Output is correct
4 Correct 566 ms 27532 KB Output is correct
5 Correct 500 ms 25688 KB Output is correct
6 Correct 667 ms 27524 KB Output is correct
7 Correct 602 ms 27528 KB Output is correct
8 Correct 595 ms 27504 KB Output is correct
9 Correct 299 ms 24024 KB Output is correct
10 Correct 536 ms 24152 KB Output is correct
11 Correct 551 ms 24152 KB Output is correct
12 Correct 529 ms 24152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 6 ms 23896 KB Output is correct
3 Correct 6 ms 23784 KB Output is correct
4 Correct 6 ms 23828 KB Output is correct
5 Correct 6 ms 23896 KB Output is correct
6 Correct 6 ms 23896 KB Output is correct
7 Correct 6 ms 23896 KB Output is correct
8 Correct 6 ms 23896 KB Output is correct
9 Correct 6 ms 23896 KB Output is correct
10 Correct 6 ms 24152 KB Output is correct
11 Correct 7 ms 24408 KB Output is correct
12 Correct 6 ms 23896 KB Output is correct
13 Correct 377 ms 25756 KB Output is correct
14 Correct 555 ms 27520 KB Output is correct
15 Correct 580 ms 27480 KB Output is correct
16 Correct 566 ms 27532 KB Output is correct
17 Correct 500 ms 25688 KB Output is correct
18 Correct 667 ms 27524 KB Output is correct
19 Correct 602 ms 27528 KB Output is correct
20 Correct 595 ms 27504 KB Output is correct
21 Correct 299 ms 24024 KB Output is correct
22 Correct 536 ms 24152 KB Output is correct
23 Correct 551 ms 24152 KB Output is correct
24 Correct 529 ms 24152 KB Output is correct
25 Correct 664 ms 29172 KB Output is correct
26 Correct 708 ms 29444 KB Output is correct
27 Correct 695 ms 29188 KB Output is correct
28 Correct 502 ms 29396 KB Output is correct
29 Correct 680 ms 49744 KB Output is correct
30 Correct 610 ms 49692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23980 KB Output is correct
6 Correct 6 ms 23932 KB Output is correct
7 Correct 5 ms 23896 KB Output is correct
8 Correct 7 ms 23896 KB Output is correct
9 Correct 5 ms 23896 KB Output is correct
10 Correct 6 ms 23896 KB Output is correct
11 Correct 6 ms 23784 KB Output is correct
12 Correct 6 ms 23828 KB Output is correct
13 Correct 6 ms 23896 KB Output is correct
14 Correct 6 ms 23896 KB Output is correct
15 Correct 6 ms 23896 KB Output is correct
16 Correct 6 ms 23896 KB Output is correct
17 Correct 6 ms 23896 KB Output is correct
18 Correct 6 ms 24152 KB Output is correct
19 Correct 7 ms 24408 KB Output is correct
20 Correct 6 ms 23896 KB Output is correct
21 Correct 6 ms 23896 KB Output is correct
22 Correct 6 ms 24152 KB Output is correct
23 Correct 6 ms 23896 KB Output is correct
24 Correct 6 ms 23896 KB Output is correct
25 Correct 6 ms 24036 KB Output is correct
26 Correct 6 ms 23896 KB Output is correct
27 Correct 7 ms 23808 KB Output is correct
28 Correct 6 ms 23896 KB Output is correct
29 Correct 6 ms 23896 KB Output is correct
30 Correct 6 ms 23896 KB Output is correct
31 Correct 6 ms 24152 KB Output is correct
32 Correct 6 ms 23896 KB Output is correct
33 Correct 6 ms 23896 KB Output is correct
34 Correct 6 ms 23896 KB Output is correct
35 Correct 6 ms 23896 KB Output is correct
36 Correct 6 ms 23972 KB Output is correct
37 Correct 6 ms 24152 KB Output is correct
38 Correct 7 ms 24152 KB Output is correct
39 Correct 6 ms 24152 KB Output is correct
40 Correct 7 ms 23896 KB Output is correct
41 Correct 6 ms 23896 KB Output is correct
42 Correct 6 ms 23896 KB Output is correct
43 Correct 406 ms 24080 KB Output is correct
44 Correct 582 ms 24112 KB Output is correct
45 Correct 581 ms 24092 KB Output is correct
46 Correct 531 ms 24220 KB Output is correct
47 Correct 564 ms 24200 KB Output is correct
48 Correct 581 ms 24204 KB Output is correct
49 Correct 574 ms 24200 KB Output is correct
50 Correct 584 ms 24196 KB Output is correct
51 Correct 522 ms 24120 KB Output is correct
52 Correct 548 ms 24124 KB Output is correct
53 Correct 504 ms 25128 KB Output is correct
54 Correct 558 ms 24200 KB Output is correct
55 Correct 592 ms 24092 KB Output is correct
56 Correct 579 ms 24076 KB Output is correct
57 Correct 549 ms 24040 KB Output is correct
58 Correct 585 ms 25208 KB Output is correct
59 Correct 539 ms 25432 KB Output is correct
60 Correct 511 ms 25312 KB Output is correct
61 Correct 565 ms 24340 KB Output is correct
62 Correct 569 ms 24060 KB Output is correct
63 Correct 596 ms 24044 KB Output is correct
64 Correct 563 ms 24068 KB Output is correct
65 Correct 288 ms 24028 KB Output is correct
66 Correct 587 ms 24152 KB Output is correct
67 Correct 636 ms 24152 KB Output is correct
68 Correct 561 ms 24152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 23896 KB Output is correct
4 Correct 5 ms 23896 KB Output is correct
5 Correct 6 ms 23980 KB Output is correct
6 Correct 6 ms 23932 KB Output is correct
7 Correct 5 ms 23896 KB Output is correct
8 Correct 7 ms 23896 KB Output is correct
9 Correct 5 ms 23896 KB Output is correct
10 Correct 6 ms 23896 KB Output is correct
11 Correct 6 ms 23784 KB Output is correct
12 Correct 6 ms 23828 KB Output is correct
13 Correct 6 ms 23896 KB Output is correct
14 Correct 6 ms 23896 KB Output is correct
15 Correct 6 ms 23896 KB Output is correct
16 Correct 6 ms 23896 KB Output is correct
17 Correct 6 ms 23896 KB Output is correct
18 Correct 6 ms 24152 KB Output is correct
19 Correct 7 ms 24408 KB Output is correct
20 Correct 6 ms 23896 KB Output is correct
21 Correct 6 ms 23896 KB Output is correct
22 Correct 6 ms 24152 KB Output is correct
23 Correct 6 ms 23896 KB Output is correct
24 Correct 6 ms 23896 KB Output is correct
25 Correct 6 ms 24036 KB Output is correct
26 Correct 6 ms 23896 KB Output is correct
27 Correct 7 ms 23808 KB Output is correct
28 Correct 6 ms 23896 KB Output is correct
29 Correct 6 ms 23896 KB Output is correct
30 Correct 6 ms 23896 KB Output is correct
31 Correct 6 ms 24152 KB Output is correct
32 Correct 6 ms 23896 KB Output is correct
33 Correct 6 ms 23896 KB Output is correct
34 Correct 6 ms 23896 KB Output is correct
35 Correct 6 ms 23896 KB Output is correct
36 Correct 6 ms 23972 KB Output is correct
37 Correct 6 ms 24152 KB Output is correct
38 Correct 7 ms 24152 KB Output is correct
39 Correct 6 ms 24152 KB Output is correct
40 Correct 7 ms 23896 KB Output is correct
41 Correct 6 ms 23896 KB Output is correct
42 Correct 6 ms 23896 KB Output is correct
43 Correct 377 ms 25756 KB Output is correct
44 Correct 555 ms 27520 KB Output is correct
45 Correct 580 ms 27480 KB Output is correct
46 Correct 566 ms 27532 KB Output is correct
47 Correct 500 ms 25688 KB Output is correct
48 Correct 667 ms 27524 KB Output is correct
49 Correct 602 ms 27528 KB Output is correct
50 Correct 595 ms 27504 KB Output is correct
51 Correct 299 ms 24024 KB Output is correct
52 Correct 536 ms 24152 KB Output is correct
53 Correct 551 ms 24152 KB Output is correct
54 Correct 529 ms 24152 KB Output is correct
55 Correct 664 ms 29172 KB Output is correct
56 Correct 708 ms 29444 KB Output is correct
57 Correct 695 ms 29188 KB Output is correct
58 Correct 502 ms 29396 KB Output is correct
59 Correct 680 ms 49744 KB Output is correct
60 Correct 610 ms 49692 KB Output is correct
61 Correct 406 ms 24080 KB Output is correct
62 Correct 582 ms 24112 KB Output is correct
63 Correct 581 ms 24092 KB Output is correct
64 Correct 531 ms 24220 KB Output is correct
65 Correct 564 ms 24200 KB Output is correct
66 Correct 581 ms 24204 KB Output is correct
67 Correct 574 ms 24200 KB Output is correct
68 Correct 584 ms 24196 KB Output is correct
69 Correct 522 ms 24120 KB Output is correct
70 Correct 548 ms 24124 KB Output is correct
71 Correct 504 ms 25128 KB Output is correct
72 Correct 558 ms 24200 KB Output is correct
73 Correct 592 ms 24092 KB Output is correct
74 Correct 579 ms 24076 KB Output is correct
75 Correct 549 ms 24040 KB Output is correct
76 Correct 585 ms 25208 KB Output is correct
77 Correct 539 ms 25432 KB Output is correct
78 Correct 511 ms 25312 KB Output is correct
79 Correct 565 ms 24340 KB Output is correct
80 Correct 569 ms 24060 KB Output is correct
81 Correct 596 ms 24044 KB Output is correct
82 Correct 563 ms 24068 KB Output is correct
83 Correct 288 ms 24028 KB Output is correct
84 Correct 587 ms 24152 KB Output is correct
85 Correct 636 ms 24152 KB Output is correct
86 Correct 561 ms 24152 KB Output is correct
87 Correct 5 ms 23896 KB Output is correct
88 Correct 398 ms 28952 KB Output is correct
89 Correct 661 ms 27636 KB Output is correct
90 Correct 645 ms 27468 KB Output is correct
91 Correct 627 ms 29744 KB Output is correct
92 Correct 737 ms 29440 KB Output is correct
93 Correct 705 ms 29528 KB Output is correct
94 Correct 692 ms 29444 KB Output is correct
95 Correct 614 ms 29528 KB Output is correct
96 Correct 570 ms 27396 KB Output is correct
97 Correct 617 ms 27408 KB Output is correct
98 Correct 524 ms 48112 KB Output is correct
99 Correct 714 ms 29188 KB Output is correct
100 Correct 764 ms 27580 KB Output is correct
101 Correct 705 ms 26960 KB Output is correct
102 Correct 746 ms 26024 KB Output is correct
103 Correct 740 ms 49664 KB Output is correct
104 Correct 712 ms 51596 KB Output is correct
105 Correct 608 ms 51600 KB Output is correct
106 Correct 622 ms 31984 KB Output is correct
107 Correct 635 ms 26616 KB Output is correct
108 Correct 657 ms 26204 KB Output is correct
109 Correct 646 ms 25972 KB Output is correct