답안 #1068959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068959 2024-08-21T13:47:22 Z beaconmc 디지털 회로 (IOI22_circuit) C++17
50 / 100
3000 ms 17440 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];




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;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    FOR(i,0,maxn) cache[i] = -1;
    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);
        states[N+i] = A[i];
        if (A[i]==1) ans += vals[N+i];
        ans %= 1000002022;
    }






}

int count_ways(int L, int R) {

    FOR(i,L,R+1){
        if (states[i]==1){
            states[i] = 0;
            ans -= vals[i];
        }else{
            states[i] = 1;
            ans += vals[i];
        }
        ans %= 1000002022;
    }
    return (ans+1000002022)%1000002022;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Correct 6 ms 11608 KB Output is correct
4 Correct 7 ms 11608 KB Output is correct
5 Correct 7 ms 11608 KB Output is correct
6 Correct 7 ms 11608 KB Output is correct
7 Correct 7 ms 11608 KB Output is correct
8 Correct 6 ms 11816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Correct 3 ms 11608 KB Output is correct
5 Correct 2 ms 11608 KB Output is correct
6 Correct 3 ms 11704 KB Output is correct
7 Correct 3 ms 11828 KB Output is correct
8 Correct 3 ms 11864 KB Output is correct
9 Correct 3 ms 11864 KB Output is correct
10 Correct 3 ms 11864 KB Output is correct
11 Correct 3 ms 11864 KB Output is correct
12 Correct 2 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Correct 6 ms 11608 KB Output is correct
4 Correct 7 ms 11608 KB Output is correct
5 Correct 7 ms 11608 KB Output is correct
6 Correct 7 ms 11608 KB Output is correct
7 Correct 7 ms 11608 KB Output is correct
8 Correct 6 ms 11816 KB Output is correct
9 Correct 2 ms 11608 KB Output is correct
10 Correct 2 ms 11608 KB Output is correct
11 Correct 2 ms 11608 KB Output is correct
12 Correct 3 ms 11608 KB Output is correct
13 Correct 2 ms 11608 KB Output is correct
14 Correct 3 ms 11704 KB Output is correct
15 Correct 3 ms 11828 KB Output is correct
16 Correct 3 ms 11864 KB Output is correct
17 Correct 3 ms 11864 KB Output is correct
18 Correct 3 ms 11864 KB Output is correct
19 Correct 3 ms 11864 KB Output is correct
20 Correct 2 ms 11864 KB Output is correct
21 Correct 2 ms 11860 KB Output is correct
22 Correct 2 ms 11608 KB Output is correct
23 Correct 2 ms 11608 KB Output is correct
24 Correct 3 ms 11864 KB Output is correct
25 Correct 2 ms 11864 KB Output is correct
26 Correct 3 ms 11864 KB Output is correct
27 Correct 2 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 7 ms 11608 KB Output is correct
30 Correct 7 ms 11608 KB Output is correct
31 Correct 3 ms 11864 KB Output is correct
32 Correct 2 ms 11864 KB Output is correct
33 Correct 3 ms 11864 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 4 ms 11608 KB Output is correct
36 Correct 2 ms 11864 KB Output is correct
37 Correct 8 ms 11864 KB Output is correct
38 Correct 6 ms 11864 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 3 ms 11608 KB Output is correct
41 Correct 3 ms 11608 KB Output is correct
42 Correct 2 ms 11608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 15448 KB Output is correct
2 Correct 591 ms 17232 KB Output is correct
3 Correct 550 ms 17440 KB Output is correct
4 Correct 543 ms 17240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 15448 KB Output is correct
2 Correct 591 ms 17232 KB Output is correct
3 Correct 550 ms 17440 KB Output is correct
4 Correct 543 ms 17240 KB Output is correct
5 Execution timed out 3065 ms 15448 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Correct 2 ms 11608 KB Output is correct
4 Correct 3 ms 11608 KB Output is correct
5 Correct 2 ms 11608 KB Output is correct
6 Correct 3 ms 11704 KB Output is correct
7 Correct 3 ms 11828 KB Output is correct
8 Correct 3 ms 11864 KB Output is correct
9 Correct 3 ms 11864 KB Output is correct
10 Correct 3 ms 11864 KB Output is correct
11 Correct 3 ms 11864 KB Output is correct
12 Correct 2 ms 11864 KB Output is correct
13 Correct 417 ms 15448 KB Output is correct
14 Correct 591 ms 17232 KB Output is correct
15 Correct 550 ms 17440 KB Output is correct
16 Correct 543 ms 17240 KB Output is correct
17 Execution timed out 3065 ms 15448 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Correct 6 ms 11608 KB Output is correct
4 Correct 7 ms 11608 KB Output is correct
5 Correct 7 ms 11608 KB Output is correct
6 Correct 7 ms 11608 KB Output is correct
7 Correct 7 ms 11608 KB Output is correct
8 Correct 6 ms 11816 KB Output is correct
9 Correct 2 ms 11608 KB Output is correct
10 Correct 2 ms 11608 KB Output is correct
11 Correct 2 ms 11608 KB Output is correct
12 Correct 3 ms 11608 KB Output is correct
13 Correct 2 ms 11608 KB Output is correct
14 Correct 3 ms 11704 KB Output is correct
15 Correct 3 ms 11828 KB Output is correct
16 Correct 3 ms 11864 KB Output is correct
17 Correct 3 ms 11864 KB Output is correct
18 Correct 3 ms 11864 KB Output is correct
19 Correct 3 ms 11864 KB Output is correct
20 Correct 2 ms 11864 KB Output is correct
21 Correct 2 ms 11860 KB Output is correct
22 Correct 2 ms 11608 KB Output is correct
23 Correct 2 ms 11608 KB Output is correct
24 Correct 3 ms 11864 KB Output is correct
25 Correct 2 ms 11864 KB Output is correct
26 Correct 3 ms 11864 KB Output is correct
27 Correct 2 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 7 ms 11608 KB Output is correct
30 Correct 7 ms 11608 KB Output is correct
31 Correct 3 ms 11864 KB Output is correct
32 Correct 2 ms 11864 KB Output is correct
33 Correct 3 ms 11864 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 4 ms 11608 KB Output is correct
36 Correct 2 ms 11864 KB Output is correct
37 Correct 8 ms 11864 KB Output is correct
38 Correct 6 ms 11864 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 3 ms 11608 KB Output is correct
41 Correct 3 ms 11608 KB Output is correct
42 Correct 2 ms 11608 KB Output is correct
43 Correct 736 ms 11864 KB Output is correct
44 Correct 943 ms 11864 KB Output is correct
45 Correct 1031 ms 11864 KB Output is correct
46 Correct 610 ms 14168 KB Output is correct
47 Correct 1270 ms 14168 KB Output is correct
48 Correct 1291 ms 14168 KB Output is correct
49 Correct 1266 ms 14168 KB Output is correct
50 Correct 2463 ms 14168 KB Output is correct
51 Correct 2577 ms 12016 KB Output is correct
52 Correct 1381 ms 12012 KB Output is correct
53 Correct 652 ms 12120 KB Output is correct
54 Correct 1270 ms 14168 KB Output is correct
55 Correct 1263 ms 11864 KB Output is correct
56 Correct 1269 ms 11864 KB Output is correct
57 Correct 1253 ms 11864 KB Output is correct
58 Correct 1259 ms 14424 KB Output is correct
59 Correct 1357 ms 14568 KB Output is correct
60 Correct 2594 ms 14572 KB Output is correct
61 Correct 921 ms 11864 KB Output is correct
62 Correct 1068 ms 11864 KB Output is correct
63 Correct 1126 ms 11864 KB Output is correct
64 Correct 1238 ms 11864 KB Output is correct
65 Correct 454 ms 11864 KB Output is correct
66 Correct 1137 ms 11864 KB Output is correct
67 Correct 1153 ms 11864 KB Output is correct
68 Correct 2183 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 11608 KB Output is correct
2 Correct 2 ms 11608 KB Output is correct
3 Correct 6 ms 11608 KB Output is correct
4 Correct 7 ms 11608 KB Output is correct
5 Correct 7 ms 11608 KB Output is correct
6 Correct 7 ms 11608 KB Output is correct
7 Correct 7 ms 11608 KB Output is correct
8 Correct 6 ms 11816 KB Output is correct
9 Correct 2 ms 11608 KB Output is correct
10 Correct 2 ms 11608 KB Output is correct
11 Correct 2 ms 11608 KB Output is correct
12 Correct 3 ms 11608 KB Output is correct
13 Correct 2 ms 11608 KB Output is correct
14 Correct 3 ms 11704 KB Output is correct
15 Correct 3 ms 11828 KB Output is correct
16 Correct 3 ms 11864 KB Output is correct
17 Correct 3 ms 11864 KB Output is correct
18 Correct 3 ms 11864 KB Output is correct
19 Correct 3 ms 11864 KB Output is correct
20 Correct 2 ms 11864 KB Output is correct
21 Correct 2 ms 11860 KB Output is correct
22 Correct 2 ms 11608 KB Output is correct
23 Correct 2 ms 11608 KB Output is correct
24 Correct 3 ms 11864 KB Output is correct
25 Correct 2 ms 11864 KB Output is correct
26 Correct 3 ms 11864 KB Output is correct
27 Correct 2 ms 11864 KB Output is correct
28 Correct 3 ms 11864 KB Output is correct
29 Correct 7 ms 11608 KB Output is correct
30 Correct 7 ms 11608 KB Output is correct
31 Correct 3 ms 11864 KB Output is correct
32 Correct 2 ms 11864 KB Output is correct
33 Correct 3 ms 11864 KB Output is correct
34 Correct 3 ms 11864 KB Output is correct
35 Correct 4 ms 11608 KB Output is correct
36 Correct 2 ms 11864 KB Output is correct
37 Correct 8 ms 11864 KB Output is correct
38 Correct 6 ms 11864 KB Output is correct
39 Correct 2 ms 11864 KB Output is correct
40 Correct 3 ms 11608 KB Output is correct
41 Correct 3 ms 11608 KB Output is correct
42 Correct 2 ms 11608 KB Output is correct
43 Correct 417 ms 15448 KB Output is correct
44 Correct 591 ms 17232 KB Output is correct
45 Correct 550 ms 17440 KB Output is correct
46 Correct 543 ms 17240 KB Output is correct
47 Execution timed out 3065 ms 15448 KB Time limit exceeded
48 Halted 0 ms 0 KB -