답안 #627315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627315 2022-08-12T12:47:29 Z jeroenodb 디지털 회로 (IOI22_circuit) C++17
100 / 100
1562 ms 15556 KB
#include "circuit.h"

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const long long MD = 1e9+2022;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){
        if(d<0) d+=MOD;
    };
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
struct segtree {
    struct node {
        mint res[2] = {};
        bool flip=0;
        node() {}
    };
    vector<node> seg;
    int n,ptwo;
    segtree() {}
    segtree(int nn) {
        n=nn,ptwo=1;
        while(ptwo<n) ptwo*=2;
        seg.resize(2*ptwo);
    }
    void puttag(int i, bool f) {
        auto& v = seg[i];
        if(f) {
            swap(v.res[0],v.res[1]);
            v.flip^=1;
        }
    }
    void pull(int i) {
        auto& v = seg[i];
        v.res[0] = seg[i*2].res[0]+seg[i*2+1].res[0];
        v.res[1] = seg[i*2].res[1]+seg[i*2+1].res[1];
    }
    void push(int i) { // TODO!
        auto& v = seg[i];
        if(v.flip) {
            puttag(i*2,v.flip);
            puttag(i*2+1,v.flip);
        }
        v.flip=false;
    }
    void set(int i, int l, int r, int ql, int qr) {
        if(qr<l or r<ql) return;
        if(ql<=l and r<=qr) {
            puttag(i,1); // correct?
            return;
        }
        int mid = (l+r)/2;
        push(i);
        set(i*2,l,mid,ql,qr),set(i*2+1,mid+1,r,ql,qr);
        pull(i);
    }
    void set(int l, int r) {
        set(1,0,ptwo-1,l,r);
    }
    node& operator[](int i) {return seg[i+ptwo];}
    void build() {
        for(int i=ptwo-1;i>=1;--i) {
            pull(i);
        }
    }
};

segtree seg;
int n;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n=N;
    vvi adj(N+M);
    for(int i=1;i<N+M;++i) {
        adj[P[i]].push_back(i);
    }
    vector<mint> degProd(N+M,1);
    for(int i=N-1;i>=0;--i) {
        degProd[i]=adj[i].size();
        for(int to : adj[i]) {
            degProd[i]*=degProd[to];
        }
    }
    vector<mint> w(N+M,1);
    for(int i=0;i<N;++i) {
       
        int c = adj[i].size();
        vector<mint> pref(c+1,1);
        for(int j=1;j<=c;++j) {
            pref[j]=pref[j-1]*degProd[adj[i][j-1]];
        }
        mint suf=1;
        for(int j=c-1;j>=0;--j) {
            w[adj[i][j]]=w[i]*pref[j]*suf;
            suf*=degProd[adj[i][j]];
        }
    }
    seg = segtree(M);
    for(int i=0;i<M;++i) {
        seg[i].res[A[i]] = w[i+N];
    }
    seg.build();
}

int count_ways(int L, int R) {
    seg.set(L-n,R-n);
    return seg.seg[1].res[1].d;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 0 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 4900 KB Output is correct
2 Correct 1016 ms 9512 KB Output is correct
3 Correct 754 ms 9496 KB Output is correct
4 Correct 814 ms 9536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 475 ms 4900 KB Output is correct
2 Correct 1016 ms 9512 KB Output is correct
3 Correct 754 ms 9496 KB Output is correct
4 Correct 814 ms 9536 KB Output is correct
5 Correct 721 ms 4896 KB Output is correct
6 Correct 919 ms 9536 KB Output is correct
7 Correct 853 ms 9500 KB Output is correct
8 Correct 990 ms 9508 KB Output is correct
9 Correct 535 ms 564 KB Output is correct
10 Correct 817 ms 848 KB Output is correct
11 Correct 953 ms 896 KB Output is correct
12 Correct 973 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 368 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 475 ms 4900 KB Output is correct
14 Correct 1016 ms 9512 KB Output is correct
15 Correct 754 ms 9496 KB Output is correct
16 Correct 814 ms 9536 KB Output is correct
17 Correct 721 ms 4896 KB Output is correct
18 Correct 919 ms 9536 KB Output is correct
19 Correct 853 ms 9500 KB Output is correct
20 Correct 990 ms 9508 KB Output is correct
21 Correct 535 ms 564 KB Output is correct
22 Correct 817 ms 848 KB Output is correct
23 Correct 953 ms 896 KB Output is correct
24 Correct 973 ms 908 KB Output is correct
25 Correct 1037 ms 14872 KB Output is correct
26 Correct 956 ms 15028 KB Output is correct
27 Correct 1022 ms 15008 KB Output is correct
28 Correct 676 ms 15032 KB Output is correct
29 Correct 874 ms 15036 KB Output is correct
30 Correct 727 ms 15028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 0 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 431 ms 720 KB Output is correct
44 Correct 616 ms 768 KB Output is correct
45 Correct 895 ms 720 KB Output is correct
46 Correct 769 ms 976 KB Output is correct
47 Correct 727 ms 976 KB Output is correct
48 Correct 774 ms 976 KB Output is correct
49 Correct 726 ms 976 KB Output is correct
50 Correct 910 ms 976 KB Output is correct
51 Correct 756 ms 720 KB Output is correct
52 Correct 841 ms 720 KB Output is correct
53 Correct 825 ms 592 KB Output is correct
54 Correct 847 ms 976 KB Output is correct
55 Correct 639 ms 848 KB Output is correct
56 Correct 839 ms 848 KB Output is correct
57 Correct 911 ms 720 KB Output is correct
58 Correct 835 ms 976 KB Output is correct
59 Correct 693 ms 1104 KB Output is correct
60 Correct 885 ms 1104 KB Output is correct
61 Correct 830 ms 720 KB Output is correct
62 Correct 891 ms 592 KB Output is correct
63 Correct 855 ms 656 KB Output is correct
64 Correct 826 ms 720 KB Output is correct
65 Correct 714 ms 564 KB Output is correct
66 Correct 743 ms 848 KB Output is correct
67 Correct 987 ms 848 KB Output is correct
68 Correct 761 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 0 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 475 ms 4900 KB Output is correct
44 Correct 1016 ms 9512 KB Output is correct
45 Correct 754 ms 9496 KB Output is correct
46 Correct 814 ms 9536 KB Output is correct
47 Correct 721 ms 4896 KB Output is correct
48 Correct 919 ms 9536 KB Output is correct
49 Correct 853 ms 9500 KB Output is correct
50 Correct 990 ms 9508 KB Output is correct
51 Correct 535 ms 564 KB Output is correct
52 Correct 817 ms 848 KB Output is correct
53 Correct 953 ms 896 KB Output is correct
54 Correct 973 ms 908 KB Output is correct
55 Correct 1037 ms 14872 KB Output is correct
56 Correct 956 ms 15028 KB Output is correct
57 Correct 1022 ms 15008 KB Output is correct
58 Correct 676 ms 15032 KB Output is correct
59 Correct 874 ms 15036 KB Output is correct
60 Correct 727 ms 15028 KB Output is correct
61 Correct 431 ms 720 KB Output is correct
62 Correct 616 ms 768 KB Output is correct
63 Correct 895 ms 720 KB Output is correct
64 Correct 769 ms 976 KB Output is correct
65 Correct 727 ms 976 KB Output is correct
66 Correct 774 ms 976 KB Output is correct
67 Correct 726 ms 976 KB Output is correct
68 Correct 910 ms 976 KB Output is correct
69 Correct 756 ms 720 KB Output is correct
70 Correct 841 ms 720 KB Output is correct
71 Correct 825 ms 592 KB Output is correct
72 Correct 847 ms 976 KB Output is correct
73 Correct 639 ms 848 KB Output is correct
74 Correct 839 ms 848 KB Output is correct
75 Correct 911 ms 720 KB Output is correct
76 Correct 835 ms 976 KB Output is correct
77 Correct 693 ms 1104 KB Output is correct
78 Correct 885 ms 1104 KB Output is correct
79 Correct 830 ms 720 KB Output is correct
80 Correct 891 ms 592 KB Output is correct
81 Correct 855 ms 656 KB Output is correct
82 Correct 826 ms 720 KB Output is correct
83 Correct 714 ms 564 KB Output is correct
84 Correct 743 ms 848 KB Output is correct
85 Correct 987 ms 848 KB Output is correct
86 Correct 761 ms 848 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 524 ms 13852 KB Output is correct
89 Correct 1059 ms 9676 KB Output is correct
90 Correct 806 ms 9244 KB Output is correct
91 Correct 957 ms 15228 KB Output is correct
92 Correct 882 ms 15156 KB Output is correct
93 Correct 993 ms 15192 KB Output is correct
94 Correct 925 ms 15220 KB Output is correct
95 Correct 896 ms 15224 KB Output is correct
96 Correct 731 ms 8588 KB Output is correct
97 Correct 806 ms 8472 KB Output is correct
98 Correct 734 ms 7260 KB Output is correct
99 Correct 1025 ms 15040 KB Output is correct
100 Correct 902 ms 11504 KB Output is correct
101 Correct 1562 ms 10260 KB Output is correct
102 Correct 887 ms 8540 KB Output is correct
103 Correct 1085 ms 15116 KB Output is correct
104 Correct 1020 ms 15552 KB Output is correct
105 Correct 680 ms 15556 KB Output is correct
106 Correct 709 ms 9256 KB Output is correct
107 Correct 1096 ms 9372 KB Output is correct
108 Correct 948 ms 9260 KB Output is correct
109 Correct 898 ms 8588 KB Output is correct