답안 #912723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912723 2024-01-19T18:56:57 Z biank 디지털 회로 (IOI22_circuit) C++17
34 / 100
3000 ms 12472 KB
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> ii; 
#define ALL(x) x.begin(),x.end()
#define SIZE(x) (int)x.size()
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define fst first
#define snd second
#define pb push_back
const int MAXN = 2e5;
const int MOD = 1e9+2022;
vi s, adj[MAXN];
int n, m;
int dp[MAXN][2];
 
int mul(int x, int y) {
    return int(1LL*x*y%MOD);
}

void add(int &x, int y) {
    x+=y;
    if(x>=MOD) x-=MOD;
}
 
void compute_dp(int u) {
    int l=2*u+1, r=2*u+2;
    
    int aux = mul(dp[l][0], dp[r][1]);
    add(aux, mul(dp[l][1], dp[r][0]));
    dp[u][1] = dp[u][0] = aux;
    
    aux = mul(mul(2, dp[l][0]), dp[r][0]);
    add(dp[u][0], aux);
    
    aux = mul(mul(2, dp[l][1]), dp[r][1]);
    add(dp[u][1], aux);
}
 
void dfs_st(int u) {
    if(u>=n) {
        dp[u][s[u-n]] = 1;
        dp[u][!s[u-n]] = 0;
        return;
    }
    dfs_st(2*u+1), dfs_st(2*u+2);
    compute_dp(u);
}
 
bool bt=true;
 
void init(int N, int M, vi P, vi A) {
    bt &= M==N+1;
    bt &= !(M&(M-1));
    s=A, n=N, m=M;
    forsn(i,1,n+m) {
        adj[P[i]].pb(i);
        bt &= P[i]==(i-1)/2;
    }
    if(bt) dfs_st(0);
}

bool lazy[MAXN];

void pass(int u) {
    if(!lazy[u]) return;
    if(2*u+2<MAXN) {
        lazy[2*u+1] ^= 1;
        lazy[2*u+2] ^= 1;
    }
    swap(dp[u][0], dp[u][1]);
    lazy[u] = false;
}

void update(int ql, int qr, int nl, int nr, int u) {
    pass(u);
    if(qr <= nl || nr <= ql) {
        return;
    }
    if(ql <= nl && nr <= qr) {
        lazy[u] ^= 1;
        pass(u);
        return;
    }
    int nm=(nl+nr)/2;
    update(ql,qr,nl,nm,2*u+1);
    update(ql,qr,nm,nr,2*u+2);
    compute_dp(u);
}
 
ii dfs(int u) {
    int c=SIZE(adj[u]);
    if(!c) return {!s[u-n], s[u-n]};
    vi ways(c+1,0);
    ways[0] = 1;
    forn(i,c) {
        ii child=dfs(adj[u][i]);
        dforn(j,c+1) {
            ways[j] = mul(ways[j],child.fst);
            if(j) add(ways[j],mul(ways[j-1],child.snd));
        }
    }
    ii ans = {0,0};
    forsn(i,1,c+1) {
        forn(j,i) add(ans.fst, ways[j]);
        forsn(j,i,c+1) add(ans.snd, ways[j]);
    }
    return ans;
}
 
int count_ways(int L, int R) {
    if(bt) {
        update(L-n, R-n+1, 0, m, 0);
        return dp[0][1];
    }
    forsn(i,L,R+1) s[i-n]^=1;
    return int(dfs(0).snd);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6740 KB Output is correct
3 Correct 23 ms 6744 KB Output is correct
4 Correct 24 ms 6744 KB Output is correct
5 Correct 24 ms 6744 KB Output is correct
6 Correct 27 ms 6744 KB Output is correct
7 Correct 24 ms 6744 KB Output is correct
8 Correct 23 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6744 KB Output is correct
5 Correct 2 ms 6744 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 2 ms 6744 KB Output is correct
8 Correct 2 ms 6744 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 3 ms 6744 KB Output is correct
11 Correct 3 ms 6744 KB Output is correct
12 Correct 2 ms 6996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6740 KB Output is correct
3 Correct 23 ms 6744 KB Output is correct
4 Correct 24 ms 6744 KB Output is correct
5 Correct 24 ms 6744 KB Output is correct
6 Correct 27 ms 6744 KB Output is correct
7 Correct 24 ms 6744 KB Output is correct
8 Correct 23 ms 6744 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 2 ms 6744 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 3 ms 6744 KB Output is correct
19 Correct 3 ms 6744 KB Output is correct
20 Correct 2 ms 6996 KB Output is correct
21 Correct 2 ms 6744 KB Output is correct
22 Correct 2 ms 6988 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 3 ms 6744 KB Output is correct
25 Correct 2 ms 6744 KB Output is correct
26 Correct 2 ms 6744 KB Output is correct
27 Correct 3 ms 6744 KB Output is correct
28 Correct 2 ms 6576 KB Output is correct
29 Correct 26 ms 6744 KB Output is correct
30 Correct 24 ms 6744 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 3 ms 6740 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 2 ms 6744 KB Output is correct
35 Correct 6 ms 6744 KB Output is correct
36 Correct 2 ms 6744 KB Output is correct
37 Correct 24 ms 6744 KB Output is correct
38 Correct 24 ms 6744 KB Output is correct
39 Correct 2 ms 6744 KB Output is correct
40 Correct 2 ms 6996 KB Output is correct
41 Correct 3 ms 6744 KB Output is correct
42 Correct 3 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 8604 KB Output is correct
2 Correct 569 ms 10580 KB Output is correct
3 Correct 541 ms 10544 KB Output is correct
4 Correct 565 ms 10596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 8604 KB Output is correct
2 Correct 569 ms 10580 KB Output is correct
3 Correct 541 ms 10544 KB Output is correct
4 Correct 565 ms 10596 KB Output is correct
5 Correct 482 ms 8788 KB Output is correct
6 Correct 591 ms 10580 KB Output is correct
7 Correct 618 ms 10580 KB Output is correct
8 Correct 553 ms 10576 KB Output is correct
9 Correct 267 ms 6744 KB Output is correct
10 Correct 515 ms 6744 KB Output is correct
11 Correct 527 ms 6744 KB Output is correct
12 Correct 559 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6744 KB Output is correct
5 Correct 2 ms 6744 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 2 ms 6744 KB Output is correct
8 Correct 2 ms 6744 KB Output is correct
9 Correct 2 ms 6744 KB Output is correct
10 Correct 3 ms 6744 KB Output is correct
11 Correct 3 ms 6744 KB Output is correct
12 Correct 2 ms 6996 KB Output is correct
13 Correct 372 ms 8604 KB Output is correct
14 Correct 569 ms 10580 KB Output is correct
15 Correct 541 ms 10544 KB Output is correct
16 Correct 565 ms 10596 KB Output is correct
17 Correct 482 ms 8788 KB Output is correct
18 Correct 591 ms 10580 KB Output is correct
19 Correct 618 ms 10580 KB Output is correct
20 Correct 553 ms 10576 KB Output is correct
21 Correct 267 ms 6744 KB Output is correct
22 Correct 515 ms 6744 KB Output is correct
23 Correct 527 ms 6744 KB Output is correct
24 Correct 559 ms 6744 KB Output is correct
25 Execution timed out 3102 ms 12472 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6740 KB Output is correct
3 Correct 23 ms 6744 KB Output is correct
4 Correct 24 ms 6744 KB Output is correct
5 Correct 24 ms 6744 KB Output is correct
6 Correct 27 ms 6744 KB Output is correct
7 Correct 24 ms 6744 KB Output is correct
8 Correct 23 ms 6744 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 2 ms 6744 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 3 ms 6744 KB Output is correct
19 Correct 3 ms 6744 KB Output is correct
20 Correct 2 ms 6996 KB Output is correct
21 Correct 2 ms 6744 KB Output is correct
22 Correct 2 ms 6988 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 3 ms 6744 KB Output is correct
25 Correct 2 ms 6744 KB Output is correct
26 Correct 2 ms 6744 KB Output is correct
27 Correct 3 ms 6744 KB Output is correct
28 Correct 2 ms 6576 KB Output is correct
29 Correct 26 ms 6744 KB Output is correct
30 Correct 24 ms 6744 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 3 ms 6740 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 2 ms 6744 KB Output is correct
35 Correct 6 ms 6744 KB Output is correct
36 Correct 2 ms 6744 KB Output is correct
37 Correct 24 ms 6744 KB Output is correct
38 Correct 24 ms 6744 KB Output is correct
39 Correct 2 ms 6744 KB Output is correct
40 Correct 2 ms 6996 KB Output is correct
41 Correct 3 ms 6744 KB Output is correct
42 Correct 3 ms 6744 KB Output is correct
43 Execution timed out 3070 ms 6744 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6740 KB Output is correct
3 Correct 23 ms 6744 KB Output is correct
4 Correct 24 ms 6744 KB Output is correct
5 Correct 24 ms 6744 KB Output is correct
6 Correct 27 ms 6744 KB Output is correct
7 Correct 24 ms 6744 KB Output is correct
8 Correct 23 ms 6744 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 6744 KB Output is correct
14 Correct 2 ms 6744 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6744 KB Output is correct
17 Correct 2 ms 6744 KB Output is correct
18 Correct 3 ms 6744 KB Output is correct
19 Correct 3 ms 6744 KB Output is correct
20 Correct 2 ms 6996 KB Output is correct
21 Correct 2 ms 6744 KB Output is correct
22 Correct 2 ms 6988 KB Output is correct
23 Correct 2 ms 6744 KB Output is correct
24 Correct 3 ms 6744 KB Output is correct
25 Correct 2 ms 6744 KB Output is correct
26 Correct 2 ms 6744 KB Output is correct
27 Correct 3 ms 6744 KB Output is correct
28 Correct 2 ms 6576 KB Output is correct
29 Correct 26 ms 6744 KB Output is correct
30 Correct 24 ms 6744 KB Output is correct
31 Correct 2 ms 6744 KB Output is correct
32 Correct 3 ms 6740 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 2 ms 6744 KB Output is correct
35 Correct 6 ms 6744 KB Output is correct
36 Correct 2 ms 6744 KB Output is correct
37 Correct 24 ms 6744 KB Output is correct
38 Correct 24 ms 6744 KB Output is correct
39 Correct 2 ms 6744 KB Output is correct
40 Correct 2 ms 6996 KB Output is correct
41 Correct 3 ms 6744 KB Output is correct
42 Correct 3 ms 6744 KB Output is correct
43 Correct 372 ms 8604 KB Output is correct
44 Correct 569 ms 10580 KB Output is correct
45 Correct 541 ms 10544 KB Output is correct
46 Correct 565 ms 10596 KB Output is correct
47 Correct 482 ms 8788 KB Output is correct
48 Correct 591 ms 10580 KB Output is correct
49 Correct 618 ms 10580 KB Output is correct
50 Correct 553 ms 10576 KB Output is correct
51 Correct 267 ms 6744 KB Output is correct
52 Correct 515 ms 6744 KB Output is correct
53 Correct 527 ms 6744 KB Output is correct
54 Correct 559 ms 6744 KB Output is correct
55 Execution timed out 3102 ms 12472 KB Time limit exceeded
56 Halted 0 ms 0 KB -