Submission #1069000

# Submission time Handle Problem Language Result Execution time Memory
1069000 2024-08-21T14:14:07 Z beaconmc Digital Circuit (IOI22_circuit) C++17
89 / 100
3000 ms 39860 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;

vector<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;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25944 KB Output is correct
2 Correct 3 ms 25944 KB Output is correct
3 Correct 8 ms 25944 KB Output is correct
4 Correct 7 ms 25944 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 8 ms 25992 KB Output is correct
7 Correct 8 ms 25944 KB Output is correct
8 Correct 8 ms 25944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25944 KB Output is correct
2 Correct 4 ms 25968 KB Output is correct
3 Correct 4 ms 25944 KB Output is correct
4 Correct 4 ms 25944 KB Output is correct
5 Correct 4 ms 25944 KB Output is correct
6 Correct 4 ms 25940 KB Output is correct
7 Correct 4 ms 25944 KB Output is correct
8 Correct 4 ms 25896 KB Output is correct
9 Correct 5 ms 25944 KB Output is correct
10 Correct 4 ms 25944 KB Output is correct
11 Correct 4 ms 25944 KB Output is correct
12 Correct 4 ms 25944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25944 KB Output is correct
2 Correct 3 ms 25944 KB Output is correct
3 Correct 8 ms 25944 KB Output is correct
4 Correct 7 ms 25944 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 8 ms 25992 KB Output is correct
7 Correct 8 ms 25944 KB Output is correct
8 Correct 8 ms 25944 KB Output is correct
9 Correct 4 ms 25944 KB Output is correct
10 Correct 4 ms 25968 KB Output is correct
11 Correct 4 ms 25944 KB Output is correct
12 Correct 4 ms 25944 KB Output is correct
13 Correct 4 ms 25944 KB Output is correct
14 Correct 4 ms 25940 KB Output is correct
15 Correct 4 ms 25944 KB Output is correct
16 Correct 4 ms 25896 KB Output is correct
17 Correct 5 ms 25944 KB Output is correct
18 Correct 4 ms 25944 KB Output is correct
19 Correct 4 ms 25944 KB Output is correct
20 Correct 4 ms 25944 KB Output is correct
21 Correct 4 ms 25944 KB Output is correct
22 Correct 3 ms 25944 KB Output is correct
23 Correct 4 ms 25944 KB Output is correct
24 Correct 4 ms 25944 KB Output is correct
25 Correct 4 ms 25944 KB Output is correct
26 Correct 4 ms 25944 KB Output is correct
27 Correct 4 ms 25944 KB Output is correct
28 Correct 4 ms 25944 KB Output is correct
29 Correct 9 ms 26104 KB Output is correct
30 Correct 8 ms 25944 KB Output is correct
31 Correct 4 ms 25944 KB Output is correct
32 Correct 5 ms 25944 KB Output is correct
33 Correct 4 ms 25944 KB Output is correct
34 Correct 4 ms 25944 KB Output is correct
35 Correct 5 ms 25944 KB Output is correct
36 Correct 4 ms 25944 KB Output is correct
37 Correct 9 ms 26200 KB Output is correct
38 Correct 9 ms 26200 KB Output is correct
39 Correct 5 ms 25944 KB Output is correct
40 Correct 5 ms 25944 KB Output is correct
41 Correct 4 ms 25944 KB Output is correct
42 Correct 5 ms 25944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 29796 KB Output is correct
2 Correct 662 ms 31716 KB Output is correct
3 Correct 675 ms 31516 KB Output is correct
4 Correct 730 ms 31548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 29796 KB Output is correct
2 Correct 662 ms 31716 KB Output is correct
3 Correct 675 ms 31516 KB Output is correct
4 Correct 730 ms 31548 KB Output is correct
5 Correct 590 ms 29784 KB Output is correct
6 Correct 778 ms 31576 KB Output is correct
7 Correct 812 ms 31576 KB Output is correct
8 Correct 690 ms 31576 KB Output is correct
9 Correct 299 ms 25944 KB Output is correct
10 Correct 657 ms 26200 KB Output is correct
11 Correct 649 ms 26200 KB Output is correct
12 Correct 692 ms 26200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25944 KB Output is correct
2 Correct 4 ms 25968 KB Output is correct
3 Correct 4 ms 25944 KB Output is correct
4 Correct 4 ms 25944 KB Output is correct
5 Correct 4 ms 25944 KB Output is correct
6 Correct 4 ms 25940 KB Output is correct
7 Correct 4 ms 25944 KB Output is correct
8 Correct 4 ms 25896 KB Output is correct
9 Correct 5 ms 25944 KB Output is correct
10 Correct 4 ms 25944 KB Output is correct
11 Correct 4 ms 25944 KB Output is correct
12 Correct 4 ms 25944 KB Output is correct
13 Correct 503 ms 29796 KB Output is correct
14 Correct 662 ms 31716 KB Output is correct
15 Correct 675 ms 31516 KB Output is correct
16 Correct 730 ms 31548 KB Output is correct
17 Correct 590 ms 29784 KB Output is correct
18 Correct 778 ms 31576 KB Output is correct
19 Correct 812 ms 31576 KB Output is correct
20 Correct 690 ms 31576 KB Output is correct
21 Correct 299 ms 25944 KB Output is correct
22 Correct 657 ms 26200 KB Output is correct
23 Correct 649 ms 26200 KB Output is correct
24 Correct 692 ms 26200 KB Output is correct
25 Correct 750 ms 33360 KB Output is correct
26 Correct 736 ms 33368 KB Output is correct
27 Correct 774 ms 33360 KB Output is correct
28 Correct 620 ms 33448 KB Output is correct
29 Correct 726 ms 39860 KB Output is correct
30 Correct 681 ms 39852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25944 KB Output is correct
2 Correct 3 ms 25944 KB Output is correct
3 Correct 8 ms 25944 KB Output is correct
4 Correct 7 ms 25944 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 8 ms 25992 KB Output is correct
7 Correct 8 ms 25944 KB Output is correct
8 Correct 8 ms 25944 KB Output is correct
9 Correct 4 ms 25944 KB Output is correct
10 Correct 4 ms 25968 KB Output is correct
11 Correct 4 ms 25944 KB Output is correct
12 Correct 4 ms 25944 KB Output is correct
13 Correct 4 ms 25944 KB Output is correct
14 Correct 4 ms 25940 KB Output is correct
15 Correct 4 ms 25944 KB Output is correct
16 Correct 4 ms 25896 KB Output is correct
17 Correct 5 ms 25944 KB Output is correct
18 Correct 4 ms 25944 KB Output is correct
19 Correct 4 ms 25944 KB Output is correct
20 Correct 4 ms 25944 KB Output is correct
21 Correct 4 ms 25944 KB Output is correct
22 Correct 3 ms 25944 KB Output is correct
23 Correct 4 ms 25944 KB Output is correct
24 Correct 4 ms 25944 KB Output is correct
25 Correct 4 ms 25944 KB Output is correct
26 Correct 4 ms 25944 KB Output is correct
27 Correct 4 ms 25944 KB Output is correct
28 Correct 4 ms 25944 KB Output is correct
29 Correct 9 ms 26104 KB Output is correct
30 Correct 8 ms 25944 KB Output is correct
31 Correct 4 ms 25944 KB Output is correct
32 Correct 5 ms 25944 KB Output is correct
33 Correct 4 ms 25944 KB Output is correct
34 Correct 4 ms 25944 KB Output is correct
35 Correct 5 ms 25944 KB Output is correct
36 Correct 4 ms 25944 KB Output is correct
37 Correct 9 ms 26200 KB Output is correct
38 Correct 9 ms 26200 KB Output is correct
39 Correct 5 ms 25944 KB Output is correct
40 Correct 5 ms 25944 KB Output is correct
41 Correct 4 ms 25944 KB Output is correct
42 Correct 5 ms 25944 KB Output is correct
43 Correct 450 ms 26200 KB Output is correct
44 Correct 669 ms 26200 KB Output is correct
45 Correct 641 ms 26200 KB Output is correct
46 Correct 593 ms 26200 KB Output is correct
47 Correct 725 ms 26200 KB Output is correct
48 Correct 651 ms 26200 KB Output is correct
49 Correct 662 ms 26200 KB Output is correct
50 Correct 641 ms 26200 KB Output is correct
51 Correct 787 ms 26236 KB Output is correct
52 Correct 763 ms 26236 KB Output is correct
53 Correct 651 ms 26456 KB Output is correct
54 Correct 638 ms 26200 KB Output is correct
55 Correct 687 ms 26200 KB Output is correct
56 Correct 717 ms 26200 KB Output is correct
57 Correct 690 ms 26196 KB Output is correct
58 Correct 582 ms 26456 KB Output is correct
59 Correct 765 ms 26740 KB Output is correct
60 Correct 680 ms 26740 KB Output is correct
61 Correct 527 ms 26200 KB Output is correct
62 Correct 525 ms 26200 KB Output is correct
63 Correct 531 ms 26200 KB Output is correct
64 Correct 591 ms 26200 KB Output is correct
65 Correct 355 ms 25956 KB Output is correct
66 Correct 672 ms 26200 KB Output is correct
67 Correct 613 ms 26200 KB Output is correct
68 Correct 628 ms 26200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25944 KB Output is correct
2 Correct 3 ms 25944 KB Output is correct
3 Correct 8 ms 25944 KB Output is correct
4 Correct 7 ms 25944 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 8 ms 25992 KB Output is correct
7 Correct 8 ms 25944 KB Output is correct
8 Correct 8 ms 25944 KB Output is correct
9 Correct 4 ms 25944 KB Output is correct
10 Correct 4 ms 25968 KB Output is correct
11 Correct 4 ms 25944 KB Output is correct
12 Correct 4 ms 25944 KB Output is correct
13 Correct 4 ms 25944 KB Output is correct
14 Correct 4 ms 25940 KB Output is correct
15 Correct 4 ms 25944 KB Output is correct
16 Correct 4 ms 25896 KB Output is correct
17 Correct 5 ms 25944 KB Output is correct
18 Correct 4 ms 25944 KB Output is correct
19 Correct 4 ms 25944 KB Output is correct
20 Correct 4 ms 25944 KB Output is correct
21 Correct 4 ms 25944 KB Output is correct
22 Correct 3 ms 25944 KB Output is correct
23 Correct 4 ms 25944 KB Output is correct
24 Correct 4 ms 25944 KB Output is correct
25 Correct 4 ms 25944 KB Output is correct
26 Correct 4 ms 25944 KB Output is correct
27 Correct 4 ms 25944 KB Output is correct
28 Correct 4 ms 25944 KB Output is correct
29 Correct 9 ms 26104 KB Output is correct
30 Correct 8 ms 25944 KB Output is correct
31 Correct 4 ms 25944 KB Output is correct
32 Correct 5 ms 25944 KB Output is correct
33 Correct 4 ms 25944 KB Output is correct
34 Correct 4 ms 25944 KB Output is correct
35 Correct 5 ms 25944 KB Output is correct
36 Correct 4 ms 25944 KB Output is correct
37 Correct 9 ms 26200 KB Output is correct
38 Correct 9 ms 26200 KB Output is correct
39 Correct 5 ms 25944 KB Output is correct
40 Correct 5 ms 25944 KB Output is correct
41 Correct 4 ms 25944 KB Output is correct
42 Correct 5 ms 25944 KB Output is correct
43 Correct 503 ms 29796 KB Output is correct
44 Correct 662 ms 31716 KB Output is correct
45 Correct 675 ms 31516 KB Output is correct
46 Correct 730 ms 31548 KB Output is correct
47 Correct 590 ms 29784 KB Output is correct
48 Correct 778 ms 31576 KB Output is correct
49 Correct 812 ms 31576 KB Output is correct
50 Correct 690 ms 31576 KB Output is correct
51 Correct 299 ms 25944 KB Output is correct
52 Correct 657 ms 26200 KB Output is correct
53 Correct 649 ms 26200 KB Output is correct
54 Correct 692 ms 26200 KB Output is correct
55 Correct 750 ms 33360 KB Output is correct
56 Correct 736 ms 33368 KB Output is correct
57 Correct 774 ms 33360 KB Output is correct
58 Correct 620 ms 33448 KB Output is correct
59 Correct 726 ms 39860 KB Output is correct
60 Correct 681 ms 39852 KB Output is correct
61 Correct 450 ms 26200 KB Output is correct
62 Correct 669 ms 26200 KB Output is correct
63 Correct 641 ms 26200 KB Output is correct
64 Correct 593 ms 26200 KB Output is correct
65 Correct 725 ms 26200 KB Output is correct
66 Correct 651 ms 26200 KB Output is correct
67 Correct 662 ms 26200 KB Output is correct
68 Correct 641 ms 26200 KB Output is correct
69 Correct 787 ms 26236 KB Output is correct
70 Correct 763 ms 26236 KB Output is correct
71 Correct 651 ms 26456 KB Output is correct
72 Correct 638 ms 26200 KB Output is correct
73 Correct 687 ms 26200 KB Output is correct
74 Correct 717 ms 26200 KB Output is correct
75 Correct 690 ms 26196 KB Output is correct
76 Correct 582 ms 26456 KB Output is correct
77 Correct 765 ms 26740 KB Output is correct
78 Correct 680 ms 26740 KB Output is correct
79 Correct 527 ms 26200 KB Output is correct
80 Correct 525 ms 26200 KB Output is correct
81 Correct 531 ms 26200 KB Output is correct
82 Correct 591 ms 26200 KB Output is correct
83 Correct 355 ms 25956 KB Output is correct
84 Correct 672 ms 26200 KB Output is correct
85 Correct 613 ms 26200 KB Output is correct
86 Correct 628 ms 26200 KB Output is correct
87 Correct 3 ms 25944 KB Output is correct
88 Correct 488 ms 33360 KB Output is correct
89 Correct 740 ms 31832 KB Output is correct
90 Correct 731 ms 31832 KB Output is correct
91 Correct 767 ms 34132 KB Output is correct
92 Correct 824 ms 34228 KB Output is correct
93 Correct 836 ms 34204 KB Output is correct
94 Correct 801 ms 34128 KB Output is correct
95 Correct 794 ms 34136 KB Output is correct
96 Execution timed out 3038 ms 30672 KB Time limit exceeded
97 Halted 0 ms 0 KB -