답안 #705532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705532 2023-03-04T15:22:21 Z danikoynov 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 8248 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll mod = 1000002022;
const int maxn = 2e5 + 10;

int n, m, p[maxn], a[maxn];
vector < int > children[maxn];
ll dp[maxn][2], temp[maxn];

void update_state(int v)
{
    dp[v][0] = dp[v][1] = 0;

    if (v >= n)
    {
        dp[v][1] = a[v - n];
        dp[v][0] = 1 - dp[v][1];
        return;
    }

    int c = children[v].size();
    for (int i = 0; i <= c; i ++)
        temp[i] = 0;

    temp[0] = 1;
    for (int u : children[v])
    {
        for (int i = c; i >= 0; i --)
        {
            temp[i] = (temp[i] * dp[u][0]) % mod;
            if (i > 0)
                temp[i] = (temp[i] + temp[i - 1] * dp[u][1]) % mod;
        }
    }


    for (int i = 0; i <= c; i ++)
    {
        dp[v][0] = (dp[v][0] + temp[i] * (ll)(c - i)) % mod;
        dp[v][1] = (dp[v][1] + temp[i] * (ll)(i)) % mod;
    }
    ///cout << v << " " << dp[v][0] << " " << dp[v][1] << endl;

}
void solve_state(int v)
{


    for (int u : children[v])
    {
        solve_state(u);
    }

    update_state(v);



}

ll pw[maxn], pref[maxn];
ll con[maxn];
int act = 0, logM = 0;
int tree[4 * maxn], lazy[4 * maxn];

void build_tree(int root, int left, int right)
{
    if (left == right)
    {
        tree[root] = (con[left] * a[left]) % mod;
        return;
    }

    int mid = (left + right) / 2;
    build_tree(root * 2, left, mid);
    build_tree(root * 2 + 1, mid + 1, right);

    tree[root] = (tree[root * 2] + tree[root * 2 + 1]) % mod;
}

ll get_sum(int left, int right)
{
    ll sum = pref[right];
    if (left != 0)
        sum = sum - pref[left - 1];
    if (sum < 0)
        sum += mod;
    return sum;
}

void push_lazy(int root, int left, int right)
{
    if (lazy[root] == 0)
        return;

    tree[root] = (get_sum(left, right) - tree[root] + mod) % mod;
    if (left != right)
    {
        lazy[root * 2] = (lazy[root * 2] + 1) % 2;
        lazy[root * 2 + 1] = (lazy[root * 2 + 1] + 1) % 2;
    }
    lazy[root] = 0;
}

void update_range(int root, int left, int right, int qleft, int qright)
{

    push_lazy(root, left, right);
    if (left > qright || right < qleft)
        return;

    if (left >= qleft && right <= qright)
    {
        lazy[root] = 1;
        push_lazy(root, left, right);
        ///cout << left << " :: " << right << " :: " << tree[root] << endl;
        return;
    }

    int mid = (left + right) / 2;
    update_range(root * 2, left, mid, qleft, qright);
    update_range(root * 2 + 1, mid + 1, right, qleft,  qright);
    ///cout << root << " " << left << " " << right << " " << qleft << " " << qright << endl;
    tree[root] = (tree[root * 2] + tree[root * 2 + 1]) % mod;
    ///cout << tree[root] << endl;
}



void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
    n = N;
    m = M;
    for (int i = 0; i < N + M; i ++)
        p[i] = P[i];


    for (int i = 1; i < N + M; i ++)
    {
        children[p[i]].push_back(i);
    }
    for (int i = 0; i < M; i ++)
    {
        a[i] = 1;
        solve_state(0);
        con[i] = dp[0][1];
        a[i] = 0;
    }
    pref[0] = con[0];
    for (int i = 1; i < M; i ++)
        pref[i] = (pref[i - 1] + con[i]) % mod;
    for (int i = 0; i < M; i ++)
        a[i] = A[i];


    build_tree(1, 0, m - 1);
}


int count_ways(int L, int R)
{
    update_range(1, 0, m - 1, L - n, R - n);
    ///for (int i = L - n; i <= R - n; i ++)
       /// a[i] = ((a[i] + 1) & 1);

    /**ll ans = 0;
    for (int i = 0; i < m; i ++)
    {

        ans = (ans + (con[i] * a[i])) % mod;
    }*/


    /**cout << "-----------" << endl;
    for (int i = 0; i < n + m; i ++)
        cout << i << " : " << dp[i][0] << " " << dp[i][1] << endl;*/

    return tree[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2641 ms 5196 KB Output is correct
4 Correct 2810 ms 5084 KB Output is correct
5 Correct 2815 ms 5192 KB Output is correct
6 Correct 2797 ms 5316 KB Output is correct
7 Correct 2796 ms 5072 KB Output is correct
8 Correct 2794 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 7 ms 5072 KB Output is correct
3 Correct 18 ms 5084 KB Output is correct
4 Correct 17 ms 5084 KB Output is correct
5 Correct 21 ms 5084 KB Output is correct
6 Correct 38 ms 5108 KB Output is correct
7 Correct 71 ms 5072 KB Output is correct
8 Correct 69 ms 5132 KB Output is correct
9 Correct 69 ms 5072 KB Output is correct
10 Correct 57 ms 5148 KB Output is correct
11 Correct 56 ms 5152 KB Output is correct
12 Correct 45 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2641 ms 5196 KB Output is correct
4 Correct 2810 ms 5084 KB Output is correct
5 Correct 2815 ms 5192 KB Output is correct
6 Correct 2797 ms 5316 KB Output is correct
7 Correct 2796 ms 5072 KB Output is correct
8 Correct 2794 ms 5200 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 7 ms 5072 KB Output is correct
11 Correct 18 ms 5084 KB Output is correct
12 Correct 17 ms 5084 KB Output is correct
13 Correct 21 ms 5084 KB Output is correct
14 Correct 38 ms 5108 KB Output is correct
15 Correct 71 ms 5072 KB Output is correct
16 Correct 69 ms 5132 KB Output is correct
17 Correct 69 ms 5072 KB Output is correct
18 Correct 57 ms 5148 KB Output is correct
19 Correct 56 ms 5152 KB Output is correct
20 Correct 45 ms 5072 KB Output is correct
21 Correct 58 ms 5100 KB Output is correct
22 Correct 27 ms 5100 KB Output is correct
23 Correct 28 ms 5096 KB Output is correct
24 Correct 81 ms 5124 KB Output is correct
25 Correct 75 ms 5072 KB Output is correct
26 Correct 78 ms 5240 KB Output is correct
27 Correct 79 ms 5136 KB Output is correct
28 Correct 74 ms 5132 KB Output is correct
29 Correct 2823 ms 5196 KB Output is correct
30 Correct 2913 ms 5204 KB Output is correct
31 Correct 3 ms 5008 KB Output is correct
32 Correct 71 ms 5124 KB Output is correct
33 Correct 50 ms 5096 KB Output is correct
34 Correct 45 ms 5072 KB Output is correct
35 Correct 524 ms 5072 KB Output is correct
36 Correct 56 ms 5152 KB Output is correct
37 Correct 2860 ms 5284 KB Output is correct
38 Correct 2923 ms 5156 KB Output is correct
39 Correct 18 ms 5200 KB Output is correct
40 Correct 41 ms 5080 KB Output is correct
41 Correct 40 ms 5088 KB Output is correct
42 Correct 100 ms 5080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3030 ms 8248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3030 ms 8248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 7 ms 5072 KB Output is correct
3 Correct 18 ms 5084 KB Output is correct
4 Correct 17 ms 5084 KB Output is correct
5 Correct 21 ms 5084 KB Output is correct
6 Correct 38 ms 5108 KB Output is correct
7 Correct 71 ms 5072 KB Output is correct
8 Correct 69 ms 5132 KB Output is correct
9 Correct 69 ms 5072 KB Output is correct
10 Correct 57 ms 5148 KB Output is correct
11 Correct 56 ms 5152 KB Output is correct
12 Correct 45 ms 5072 KB Output is correct
13 Execution timed out 3030 ms 8248 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2641 ms 5196 KB Output is correct
4 Correct 2810 ms 5084 KB Output is correct
5 Correct 2815 ms 5192 KB Output is correct
6 Correct 2797 ms 5316 KB Output is correct
7 Correct 2796 ms 5072 KB Output is correct
8 Correct 2794 ms 5200 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 7 ms 5072 KB Output is correct
11 Correct 18 ms 5084 KB Output is correct
12 Correct 17 ms 5084 KB Output is correct
13 Correct 21 ms 5084 KB Output is correct
14 Correct 38 ms 5108 KB Output is correct
15 Correct 71 ms 5072 KB Output is correct
16 Correct 69 ms 5132 KB Output is correct
17 Correct 69 ms 5072 KB Output is correct
18 Correct 57 ms 5148 KB Output is correct
19 Correct 56 ms 5152 KB Output is correct
20 Correct 45 ms 5072 KB Output is correct
21 Correct 58 ms 5100 KB Output is correct
22 Correct 27 ms 5100 KB Output is correct
23 Correct 28 ms 5096 KB Output is correct
24 Correct 81 ms 5124 KB Output is correct
25 Correct 75 ms 5072 KB Output is correct
26 Correct 78 ms 5240 KB Output is correct
27 Correct 79 ms 5136 KB Output is correct
28 Correct 74 ms 5132 KB Output is correct
29 Correct 2823 ms 5196 KB Output is correct
30 Correct 2913 ms 5204 KB Output is correct
31 Correct 3 ms 5008 KB Output is correct
32 Correct 71 ms 5124 KB Output is correct
33 Correct 50 ms 5096 KB Output is correct
34 Correct 45 ms 5072 KB Output is correct
35 Correct 524 ms 5072 KB Output is correct
36 Correct 56 ms 5152 KB Output is correct
37 Correct 2860 ms 5284 KB Output is correct
38 Correct 2923 ms 5156 KB Output is correct
39 Correct 18 ms 5200 KB Output is correct
40 Correct 41 ms 5080 KB Output is correct
41 Correct 40 ms 5088 KB Output is correct
42 Correct 100 ms 5080 KB Output is correct
43 Correct 1202 ms 5316 KB Output is correct
44 Correct 1490 ms 5356 KB Output is correct
45 Correct 1579 ms 5576 KB Output is correct
46 Correct 2862 ms 5616 KB Output is correct
47 Correct 2918 ms 5888 KB Output is correct
48 Correct 2775 ms 5652 KB Output is correct
49 Correct 2760 ms 5636 KB Output is correct
50 Correct 2996 ms 5896 KB Output is correct
51 Execution timed out 3068 ms 5280 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2641 ms 5196 KB Output is correct
4 Correct 2810 ms 5084 KB Output is correct
5 Correct 2815 ms 5192 KB Output is correct
6 Correct 2797 ms 5316 KB Output is correct
7 Correct 2796 ms 5072 KB Output is correct
8 Correct 2794 ms 5200 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 7 ms 5072 KB Output is correct
11 Correct 18 ms 5084 KB Output is correct
12 Correct 17 ms 5084 KB Output is correct
13 Correct 21 ms 5084 KB Output is correct
14 Correct 38 ms 5108 KB Output is correct
15 Correct 71 ms 5072 KB Output is correct
16 Correct 69 ms 5132 KB Output is correct
17 Correct 69 ms 5072 KB Output is correct
18 Correct 57 ms 5148 KB Output is correct
19 Correct 56 ms 5152 KB Output is correct
20 Correct 45 ms 5072 KB Output is correct
21 Correct 58 ms 5100 KB Output is correct
22 Correct 27 ms 5100 KB Output is correct
23 Correct 28 ms 5096 KB Output is correct
24 Correct 81 ms 5124 KB Output is correct
25 Correct 75 ms 5072 KB Output is correct
26 Correct 78 ms 5240 KB Output is correct
27 Correct 79 ms 5136 KB Output is correct
28 Correct 74 ms 5132 KB Output is correct
29 Correct 2823 ms 5196 KB Output is correct
30 Correct 2913 ms 5204 KB Output is correct
31 Correct 3 ms 5008 KB Output is correct
32 Correct 71 ms 5124 KB Output is correct
33 Correct 50 ms 5096 KB Output is correct
34 Correct 45 ms 5072 KB Output is correct
35 Correct 524 ms 5072 KB Output is correct
36 Correct 56 ms 5152 KB Output is correct
37 Correct 2860 ms 5284 KB Output is correct
38 Correct 2923 ms 5156 KB Output is correct
39 Correct 18 ms 5200 KB Output is correct
40 Correct 41 ms 5080 KB Output is correct
41 Correct 40 ms 5088 KB Output is correct
42 Correct 100 ms 5080 KB Output is correct
43 Execution timed out 3030 ms 8248 KB Time limit exceeded
44 Halted 0 ms 0 KB -