답안 #1069003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069003 2024-08-21T14:16:02 Z beaconmc 디지털 회로 (IOI22_circuit) C++17
89 / 100
3000 ms 41304 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)

const ll maxn = 200005;

basic_string<ll> edges[maxn];
ll sub[maxn];
ll realsub[maxn];
ll par[maxn];
ll prod[maxn];
ll prefs[maxn];


void dfs(ll a){
    prod[a] = 1;

    for (auto&i : edges[a]){
        dfs(i);

        prod[a] *= prod[i];
        prod[a] %= 1000002022;
    }
    if ( edges[a].size() != 0) prod[a] *= edges[a].size();
    prod[a] %= 1000002022;
}

ll cache[maxn];

ll dp(ll a){

    if (cache[a] != -1) return cache[a];
    if (a==0) return 1;


    cache[a] = dp(par[a]);
    for (auto&i : edges[par[a]]){
        if (i != a) cache[a] *= prod[i];
        cache[a] %= 1000002022;
    }



    return cache[a] %= 1000002022;
}
ll states[maxn];
ll vals[maxn];

ll ans = 0;
ll n;

ll tree[maxn*4];
ll lazy[maxn*4];


ll calc(ll k, ll x, ll y){
    if (lazy[k]%2==1){
        return prefs[y] - prefs[x] + vals[x] - tree[k];
    }else{
        return tree[k];
    }
}
void push(ll k, ll x, ll y){

    lazy[k*2] += lazy[k];
    lazy[k*2+1] += lazy[k];

    tree[k] = prefs[y] - prefs[x] + vals[x] - tree[k];

    lazy[k] = 0;
}
void update(ll a, ll b, ll k=1, ll x =0, ll y = n-1){
    if (y<a || b<x) return;
    if (a<=x && y<=b){
        lazy[k]++;
        return;
    }

    push(k,x,y);
    ll mid = (x+y)/2;

    update(a,b,k*2,x,mid);
    update(a,b,k*2+1,mid+1,y);

    tree[k] = calc(k*2,x,mid) + calc(k*2+1, mid+1, y);
}
void sets(ll a, ll b, ll val, ll k=1, ll x =0, ll y = n-1){
    if (y<a || b<x) return;
    if (a<=x && y<=b){
        tree[k] = val;
        return;
    }
    ll mid = (x+y)/2;

    sets(a,b,val,k*2,x,mid);
    sets(a,b,val,k*2+1,mid+1,y);

    tree[k] = calc(k*2,x,mid) + calc(k*2+1, mid+1, y);
}

ll query(ll a, ll b, ll k=1, ll x =0, ll y = n-1){
 
    if (y<a || b<x) return 0;
    if (a<=x && y<=b){

        return calc(k,x,y);
    }
    push(k,x,y);
    ll mid = (x+y)/2;
    return query(a,b,k*2,x,mid) + query(a,b,k*2+1,mid+1,y);
}


void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N+M;
    FOR(i,0,maxn) cache[i] = -1, prefs[i] = 0;
    FOR(i,0,4*maxn) tree[i] = 0, lazy[i] = 0;
    par[0] = -1;
    FOR(i,1,N+M){
        edges[P[i]].push_back(i);
        par[i] = P[i];
    }
    dfs(0);

    FOR(i,0,M){
        vals[N+i] = dp(N+i);
        sets(N+i, N+i, vals[N+i]);
    }


    FOR(i,0,N) prefs[i] = 0;
    FOR(i,N,N+M){
        prefs[i] = prefs[i-1] + vals[i];
    }
    FOR(i,0,M){
        if (A[i] == 0) update(N+i,N+i);
    }

}



int count_ways(int L, int R) {

    update(L, R);
    return (query(0,n-1)+1000002022)%1000002022;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27480 KB Output is correct
2 Correct 4 ms 27480 KB Output is correct
3 Correct 7 ms 27480 KB Output is correct
4 Correct 8 ms 27480 KB Output is correct
5 Correct 8 ms 27480 KB Output is correct
6 Correct 8 ms 27480 KB Output is correct
7 Correct 8 ms 27648 KB Output is correct
8 Correct 8 ms 27480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27480 KB Output is correct
2 Correct 3 ms 27480 KB Output is correct
3 Correct 4 ms 27480 KB Output is correct
4 Correct 4 ms 27480 KB Output is correct
5 Correct 4 ms 27480 KB Output is correct
6 Correct 4 ms 27480 KB Output is correct
7 Correct 4 ms 27480 KB Output is correct
8 Correct 5 ms 27480 KB Output is correct
9 Correct 4 ms 27480 KB Output is correct
10 Correct 6 ms 27732 KB Output is correct
11 Correct 4 ms 27736 KB Output is correct
12 Correct 4 ms 27480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27480 KB Output is correct
2 Correct 4 ms 27480 KB Output is correct
3 Correct 7 ms 27480 KB Output is correct
4 Correct 8 ms 27480 KB Output is correct
5 Correct 8 ms 27480 KB Output is correct
6 Correct 8 ms 27480 KB Output is correct
7 Correct 8 ms 27648 KB Output is correct
8 Correct 8 ms 27480 KB Output is correct
9 Correct 3 ms 27480 KB Output is correct
10 Correct 3 ms 27480 KB Output is correct
11 Correct 4 ms 27480 KB Output is correct
12 Correct 4 ms 27480 KB Output is correct
13 Correct 4 ms 27480 KB Output is correct
14 Correct 4 ms 27480 KB Output is correct
15 Correct 4 ms 27480 KB Output is correct
16 Correct 5 ms 27480 KB Output is correct
17 Correct 4 ms 27480 KB Output is correct
18 Correct 6 ms 27732 KB Output is correct
19 Correct 4 ms 27736 KB Output is correct
20 Correct 4 ms 27480 KB Output is correct
21 Correct 4 ms 27480 KB Output is correct
22 Correct 3 ms 27480 KB Output is correct
23 Correct 3 ms 27660 KB Output is correct
24 Correct 4 ms 27480 KB Output is correct
25 Correct 4 ms 27480 KB Output is correct
26 Correct 4 ms 27672 KB Output is correct
27 Correct 4 ms 27480 KB Output is correct
28 Correct 4 ms 27480 KB Output is correct
29 Correct 8 ms 27508 KB Output is correct
30 Correct 8 ms 27480 KB Output is correct
31 Correct 3 ms 27480 KB Output is correct
32 Correct 4 ms 27480 KB Output is correct
33 Correct 5 ms 27480 KB Output is correct
34 Correct 4 ms 27480 KB Output is correct
35 Correct 5 ms 27480 KB Output is correct
36 Correct 4 ms 27736 KB Output is correct
37 Correct 9 ms 27736 KB Output is correct
38 Correct 8 ms 27736 KB Output is correct
39 Correct 4 ms 27480 KB Output is correct
40 Correct 4 ms 27480 KB Output is correct
41 Correct 3 ms 27480 KB Output is correct
42 Correct 5 ms 27480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 31320 KB Output is correct
2 Correct 712 ms 33112 KB Output is correct
3 Correct 652 ms 33112 KB Output is correct
4 Correct 721 ms 33288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 510 ms 31320 KB Output is correct
2 Correct 712 ms 33112 KB Output is correct
3 Correct 652 ms 33112 KB Output is correct
4 Correct 721 ms 33288 KB Output is correct
5 Correct 564 ms 31320 KB Output is correct
6 Correct 725 ms 33304 KB Output is correct
7 Correct 733 ms 33112 KB Output is correct
8 Correct 698 ms 33112 KB Output is correct
9 Correct 345 ms 27736 KB Output is correct
10 Correct 613 ms 27736 KB Output is correct
11 Correct 636 ms 27736 KB Output is correct
12 Correct 629 ms 27736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27480 KB Output is correct
2 Correct 3 ms 27480 KB Output is correct
3 Correct 4 ms 27480 KB Output is correct
4 Correct 4 ms 27480 KB Output is correct
5 Correct 4 ms 27480 KB Output is correct
6 Correct 4 ms 27480 KB Output is correct
7 Correct 4 ms 27480 KB Output is correct
8 Correct 5 ms 27480 KB Output is correct
9 Correct 4 ms 27480 KB Output is correct
10 Correct 6 ms 27732 KB Output is correct
11 Correct 4 ms 27736 KB Output is correct
12 Correct 4 ms 27480 KB Output is correct
13 Correct 510 ms 31320 KB Output is correct
14 Correct 712 ms 33112 KB Output is correct
15 Correct 652 ms 33112 KB Output is correct
16 Correct 721 ms 33288 KB Output is correct
17 Correct 564 ms 31320 KB Output is correct
18 Correct 725 ms 33304 KB Output is correct
19 Correct 733 ms 33112 KB Output is correct
20 Correct 698 ms 33112 KB Output is correct
21 Correct 345 ms 27736 KB Output is correct
22 Correct 613 ms 27736 KB Output is correct
23 Correct 636 ms 27736 KB Output is correct
24 Correct 629 ms 27736 KB Output is correct
25 Correct 741 ms 34896 KB Output is correct
26 Correct 774 ms 35152 KB Output is correct
27 Correct 774 ms 35120 KB Output is correct
28 Correct 637 ms 35160 KB Output is correct
29 Correct 796 ms 41292 KB Output is correct
30 Correct 676 ms 41304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27480 KB Output is correct
2 Correct 4 ms 27480 KB Output is correct
3 Correct 7 ms 27480 KB Output is correct
4 Correct 8 ms 27480 KB Output is correct
5 Correct 8 ms 27480 KB Output is correct
6 Correct 8 ms 27480 KB Output is correct
7 Correct 8 ms 27648 KB Output is correct
8 Correct 8 ms 27480 KB Output is correct
9 Correct 3 ms 27480 KB Output is correct
10 Correct 3 ms 27480 KB Output is correct
11 Correct 4 ms 27480 KB Output is correct
12 Correct 4 ms 27480 KB Output is correct
13 Correct 4 ms 27480 KB Output is correct
14 Correct 4 ms 27480 KB Output is correct
15 Correct 4 ms 27480 KB Output is correct
16 Correct 5 ms 27480 KB Output is correct
17 Correct 4 ms 27480 KB Output is correct
18 Correct 6 ms 27732 KB Output is correct
19 Correct 4 ms 27736 KB Output is correct
20 Correct 4 ms 27480 KB Output is correct
21 Correct 4 ms 27480 KB Output is correct
22 Correct 3 ms 27480 KB Output is correct
23 Correct 3 ms 27660 KB Output is correct
24 Correct 4 ms 27480 KB Output is correct
25 Correct 4 ms 27480 KB Output is correct
26 Correct 4 ms 27672 KB Output is correct
27 Correct 4 ms 27480 KB Output is correct
28 Correct 4 ms 27480 KB Output is correct
29 Correct 8 ms 27508 KB Output is correct
30 Correct 8 ms 27480 KB Output is correct
31 Correct 3 ms 27480 KB Output is correct
32 Correct 4 ms 27480 KB Output is correct
33 Correct 5 ms 27480 KB Output is correct
34 Correct 4 ms 27480 KB Output is correct
35 Correct 5 ms 27480 KB Output is correct
36 Correct 4 ms 27736 KB Output is correct
37 Correct 9 ms 27736 KB Output is correct
38 Correct 8 ms 27736 KB Output is correct
39 Correct 4 ms 27480 KB Output is correct
40 Correct 4 ms 27480 KB Output is correct
41 Correct 3 ms 27480 KB Output is correct
42 Correct 5 ms 27480 KB Output is correct
43 Correct 473 ms 27736 KB Output is correct
44 Correct 672 ms 27736 KB Output is correct
45 Correct 639 ms 27736 KB Output is correct
46 Correct 688 ms 27736 KB Output is correct
47 Correct 686 ms 27736 KB Output is correct
48 Correct 693 ms 27736 KB Output is correct
49 Correct 726 ms 27736 KB Output is correct
50 Correct 677 ms 27736 KB Output is correct
51 Correct 764 ms 27804 KB Output is correct
52 Correct 760 ms 27800 KB Output is correct
53 Correct 637 ms 27992 KB Output is correct
54 Correct 681 ms 27736 KB Output is correct
55 Correct 722 ms 27736 KB Output is correct
56 Correct 695 ms 27736 KB Output is correct
57 Correct 646 ms 27736 KB Output is correct
58 Correct 655 ms 27992 KB Output is correct
59 Correct 791 ms 28152 KB Output is correct
60 Correct 772 ms 28152 KB Output is correct
61 Correct 672 ms 27736 KB Output is correct
62 Correct 679 ms 27736 KB Output is correct
63 Correct 712 ms 27736 KB Output is correct
64 Correct 676 ms 27736 KB Output is correct
65 Correct 302 ms 27736 KB Output is correct
66 Correct 671 ms 27736 KB Output is correct
67 Correct 660 ms 27736 KB Output is correct
68 Correct 645 ms 27736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 27480 KB Output is correct
2 Correct 4 ms 27480 KB Output is correct
3 Correct 7 ms 27480 KB Output is correct
4 Correct 8 ms 27480 KB Output is correct
5 Correct 8 ms 27480 KB Output is correct
6 Correct 8 ms 27480 KB Output is correct
7 Correct 8 ms 27648 KB Output is correct
8 Correct 8 ms 27480 KB Output is correct
9 Correct 3 ms 27480 KB Output is correct
10 Correct 3 ms 27480 KB Output is correct
11 Correct 4 ms 27480 KB Output is correct
12 Correct 4 ms 27480 KB Output is correct
13 Correct 4 ms 27480 KB Output is correct
14 Correct 4 ms 27480 KB Output is correct
15 Correct 4 ms 27480 KB Output is correct
16 Correct 5 ms 27480 KB Output is correct
17 Correct 4 ms 27480 KB Output is correct
18 Correct 6 ms 27732 KB Output is correct
19 Correct 4 ms 27736 KB Output is correct
20 Correct 4 ms 27480 KB Output is correct
21 Correct 4 ms 27480 KB Output is correct
22 Correct 3 ms 27480 KB Output is correct
23 Correct 3 ms 27660 KB Output is correct
24 Correct 4 ms 27480 KB Output is correct
25 Correct 4 ms 27480 KB Output is correct
26 Correct 4 ms 27672 KB Output is correct
27 Correct 4 ms 27480 KB Output is correct
28 Correct 4 ms 27480 KB Output is correct
29 Correct 8 ms 27508 KB Output is correct
30 Correct 8 ms 27480 KB Output is correct
31 Correct 3 ms 27480 KB Output is correct
32 Correct 4 ms 27480 KB Output is correct
33 Correct 5 ms 27480 KB Output is correct
34 Correct 4 ms 27480 KB Output is correct
35 Correct 5 ms 27480 KB Output is correct
36 Correct 4 ms 27736 KB Output is correct
37 Correct 9 ms 27736 KB Output is correct
38 Correct 8 ms 27736 KB Output is correct
39 Correct 4 ms 27480 KB Output is correct
40 Correct 4 ms 27480 KB Output is correct
41 Correct 3 ms 27480 KB Output is correct
42 Correct 5 ms 27480 KB Output is correct
43 Correct 510 ms 31320 KB Output is correct
44 Correct 712 ms 33112 KB Output is correct
45 Correct 652 ms 33112 KB Output is correct
46 Correct 721 ms 33288 KB Output is correct
47 Correct 564 ms 31320 KB Output is correct
48 Correct 725 ms 33304 KB Output is correct
49 Correct 733 ms 33112 KB Output is correct
50 Correct 698 ms 33112 KB Output is correct
51 Correct 345 ms 27736 KB Output is correct
52 Correct 613 ms 27736 KB Output is correct
53 Correct 636 ms 27736 KB Output is correct
54 Correct 629 ms 27736 KB Output is correct
55 Correct 741 ms 34896 KB Output is correct
56 Correct 774 ms 35152 KB Output is correct
57 Correct 774 ms 35120 KB Output is correct
58 Correct 637 ms 35160 KB Output is correct
59 Correct 796 ms 41292 KB Output is correct
60 Correct 676 ms 41304 KB Output is correct
61 Correct 473 ms 27736 KB Output is correct
62 Correct 672 ms 27736 KB Output is correct
63 Correct 639 ms 27736 KB Output is correct
64 Correct 688 ms 27736 KB Output is correct
65 Correct 686 ms 27736 KB Output is correct
66 Correct 693 ms 27736 KB Output is correct
67 Correct 726 ms 27736 KB Output is correct
68 Correct 677 ms 27736 KB Output is correct
69 Correct 764 ms 27804 KB Output is correct
70 Correct 760 ms 27800 KB Output is correct
71 Correct 637 ms 27992 KB Output is correct
72 Correct 681 ms 27736 KB Output is correct
73 Correct 722 ms 27736 KB Output is correct
74 Correct 695 ms 27736 KB Output is correct
75 Correct 646 ms 27736 KB Output is correct
76 Correct 655 ms 27992 KB Output is correct
77 Correct 791 ms 28152 KB Output is correct
78 Correct 772 ms 28152 KB Output is correct
79 Correct 672 ms 27736 KB Output is correct
80 Correct 679 ms 27736 KB Output is correct
81 Correct 712 ms 27736 KB Output is correct
82 Correct 676 ms 27736 KB Output is correct
83 Correct 302 ms 27736 KB Output is correct
84 Correct 671 ms 27736 KB Output is correct
85 Correct 660 ms 27736 KB Output is correct
86 Correct 645 ms 27736 KB Output is correct
87 Correct 4 ms 27480 KB Output is correct
88 Correct 438 ms 33268 KB Output is correct
89 Correct 752 ms 32600 KB Output is correct
90 Correct 793 ms 32344 KB Output is correct
91 Correct 784 ms 34136 KB Output is correct
92 Correct 745 ms 34136 KB Output is correct
93 Correct 825 ms 34208 KB Output is correct
94 Correct 764 ms 34132 KB Output is correct
95 Correct 747 ms 34212 KB Output is correct
96 Execution timed out 3047 ms 32208 KB Time limit exceeded
97 Halted 0 ms 0 KB -