답안 #1054467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054467 2024-08-12T10:06:47 Z shmax 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 11484 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;
using i32 = int;
#define int long long
#define len(x) ((int)(x.size()))
template<typename T>
using vec = vector<T>;

template<typename T>
using graph = vec<vec<T>>;

vec<int> cur;
graph<int> g;
int n, m;


#define mod 1000002022

int sum(int a, int b) {
    return (a + b) - (a + b >= mod ? mod : 0);
}

int sub(int a, int b) {
    return (a - b + mod) - ((a - b + mod) >= mod ? mod : 0);
}

int mult(int a, int b) {
    return (a * b) % mod;
}

int bin_pow(int a, int b) {
    int r = 1;
    while (b) {
        if (b & 1)
            r = mult(r, a);
        a = mult(a, a);
        b >>= 1;
    }
    return r;
}


const int maxN = 1e5 + 5;


struct vertex {
    int length;
    int cur_sum;
};

vertex stree[maxN * 4];
bool pushes[maxN * 4];

void init() {
    memset(stree, 0, sizeof(stree));
    memset(pushes, 0, sizeof(pushes));
}

void push(int v, int tl, int tr) {
    if (!pushes[v]) return;
    if (tl != tr) {
        pushes[v * 2] ^= 1;
        pushes[v * 2 + 1] ^= 1;
        stree[v * 2].cur_sum = sub(stree[v * 2].length, stree[v * 2].cur_sum);
        stree[v * 2 + 1].cur_sum = sub(stree[v * 2 + 1].length, stree[v * 2 + 1].cur_sum);
    }
    pushes[v] = false;
}

void build(int v, int tl, int tr, vec<int> &length) {
    if (tl == tr) {
        stree[v].length = length[tl];
        stree[v].cur_sum = 0;
        return;
    }
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, length);
    build(v * 2 + 1, tm + 1, tr, length);
    stree[v].length = sum(stree[v * 2].length, stree[v * 2 + 1].length);
    stree[v].cur_sum = 0;
}


void update(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if (tl == l and tr == r) {
        stree[v].cur_sum = sub(stree[v].length, stree[v].cur_sum);
        pushes[v] ^= 1;
        push(v, tl, tr);
        return;
    }
    int tm = (tl + tr) / 2;
    if (r <= tm) {
        update(v * 2, tl, tm, l, r);
    } else if (l > tm) {
        update(v * 2 + 1, tm + 1, tr, l, r);
    } else {
        update(v * 2, tl, tm, l, tm);
        update(v * 2 + 1, tm + 1, tr, tm + 1, r);
    }
    stree[v].cur_sum = sum(stree[v * 2].cur_sum, stree[v * 2 + 1].cur_sum);
    stree[v].length = sum(stree[v * 2].length, stree[v * 2 + 1].length);
}


int get(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if (tl == l and tr == r) {
        return stree[v].cur_sum;
    }
    int tm = (tl + tr) / 2;
    if (r <= tm) {
        return get(v * 2, tl, tm, l, r);
    } else if (l > tm) {
        return get(v * 2 + 1, tm + 1, tr, l, r);
    } else {
        return sum(get(v * 2, tl, tm, l, tm), get(v * 2 + 1, tm + 1, tr, tm + 1, r));
    }
}

void init(i32 N, i32 M, std::vector<i32> P, std::vector<i32> A) {
    n = N;
    m = M;
    g.resize(n + m);
    for (int i = 1; i < len(P); i++) {
        g[P[i]].push_back(i);
    }
    for (int i = 0; i < m; i++) {
        cur.push_back(A[i]);
    }
    int depth = 0;
    vec<int> d(n + m, 0);
    function<void(int)> dfs = [&](int v) {
        d[v] = depth;
        for (auto u: g[v]) {
            depth++;
            dfs(u);
            depth--;
        }
    };
    dfs(0);
    init();
    vec<int> dists(m);
    for (int i = n; i < m + n; i++) {
        vec<bool> mark(n+m, false);
        int cur_v = i;
        while (cur_v != 0) {
            mark[cur_v] = true;
            cur_v = P[cur_v];
        }
        mark[0] = true;
        int contrib = 1;
        for (int j = 0; j < n; j++) {
            if (!mark[j]) {
                contrib = mult(contrib, len(g[j]));
            }
        }
        dists[i - n] = contrib;
    }
    build(1, 0, m - 1, dists);
    for (int i = 0; i < m; i++) {
        if (cur[i] == 1) {
            update(1, 0, m - 1, i, i);
        }
    }

}

i32 count_ways(i32 L, i32 R) {
    L -= n;
    R -= n;
    update(1, 0, m - 1, L, R);
    int cur_sum = get(1, 0, m - 1, 0, m - 1);
    return cur_sum;
}
//422283126
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7252 KB Output is correct
2 Correct 1 ms 7000 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 1 ms 7000 KB Output is correct
5 Correct 1 ms 7000 KB Output is correct
6 Correct 1 ms 7000 KB Output is correct
7 Correct 1 ms 7000 KB Output is correct
8 Correct 1 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7000 KB Output is correct
2 Correct 1 ms 7000 KB Output is correct
3 Correct 2 ms 7000 KB Output is correct
4 Correct 2 ms 7156 KB Output is correct
5 Correct 2 ms 7000 KB Output is correct
6 Correct 3 ms 7000 KB Output is correct
7 Correct 5 ms 7224 KB Output is correct
8 Correct 5 ms 7000 KB Output is correct
9 Correct 4 ms 7000 KB Output is correct
10 Correct 4 ms 7256 KB Output is correct
11 Correct 4 ms 7256 KB Output is correct
12 Correct 4 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7252 KB Output is correct
2 Correct 1 ms 7000 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 1 ms 7000 KB Output is correct
5 Correct 1 ms 7000 KB Output is correct
6 Correct 1 ms 7000 KB Output is correct
7 Correct 1 ms 7000 KB Output is correct
8 Correct 1 ms 7000 KB Output is correct
9 Correct 1 ms 7000 KB Output is correct
10 Correct 1 ms 7000 KB Output is correct
11 Correct 2 ms 7000 KB Output is correct
12 Correct 2 ms 7156 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
14 Correct 3 ms 7000 KB Output is correct
15 Correct 5 ms 7224 KB Output is correct
16 Correct 5 ms 7000 KB Output is correct
17 Correct 4 ms 7000 KB Output is correct
18 Correct 4 ms 7256 KB Output is correct
19 Correct 4 ms 7256 KB Output is correct
20 Correct 4 ms 7000 KB Output is correct
21 Correct 4 ms 7000 KB Output is correct
22 Correct 2 ms 7000 KB Output is correct
23 Correct 2 ms 7176 KB Output is correct
24 Correct 5 ms 7240 KB Output is correct
25 Correct 5 ms 7000 KB Output is correct
26 Correct 5 ms 7000 KB Output is correct
27 Correct 5 ms 7000 KB Output is correct
28 Correct 5 ms 7000 KB Output is correct
29 Correct 1 ms 7000 KB Output is correct
30 Correct 2 ms 7000 KB Output is correct
31 Correct 1 ms 7000 KB Output is correct
32 Correct 5 ms 7000 KB Output is correct
33 Correct 3 ms 7000 KB Output is correct
34 Correct 2 ms 7000 KB Output is correct
35 Correct 1 ms 7000 KB Output is correct
36 Correct 5 ms 7256 KB Output is correct
37 Correct 4 ms 7256 KB Output is correct
38 Correct 3 ms 7288 KB Output is correct
39 Correct 2 ms 7000 KB Output is correct
40 Correct 2 ms 7000 KB Output is correct
41 Correct 2 ms 7184 KB Output is correct
42 Correct 1 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3055 ms 11484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3055 ms 11484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7000 KB Output is correct
2 Correct 1 ms 7000 KB Output is correct
3 Correct 2 ms 7000 KB Output is correct
4 Correct 2 ms 7156 KB Output is correct
5 Correct 2 ms 7000 KB Output is correct
6 Correct 3 ms 7000 KB Output is correct
7 Correct 5 ms 7224 KB Output is correct
8 Correct 5 ms 7000 KB Output is correct
9 Correct 4 ms 7000 KB Output is correct
10 Correct 4 ms 7256 KB Output is correct
11 Correct 4 ms 7256 KB Output is correct
12 Correct 4 ms 7000 KB Output is correct
13 Execution timed out 3055 ms 11484 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7252 KB Output is correct
2 Correct 1 ms 7000 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 1 ms 7000 KB Output is correct
5 Correct 1 ms 7000 KB Output is correct
6 Correct 1 ms 7000 KB Output is correct
7 Correct 1 ms 7000 KB Output is correct
8 Correct 1 ms 7000 KB Output is correct
9 Correct 1 ms 7000 KB Output is correct
10 Correct 1 ms 7000 KB Output is correct
11 Correct 2 ms 7000 KB Output is correct
12 Correct 2 ms 7156 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
14 Correct 3 ms 7000 KB Output is correct
15 Correct 5 ms 7224 KB Output is correct
16 Correct 5 ms 7000 KB Output is correct
17 Correct 4 ms 7000 KB Output is correct
18 Correct 4 ms 7256 KB Output is correct
19 Correct 4 ms 7256 KB Output is correct
20 Correct 4 ms 7000 KB Output is correct
21 Correct 4 ms 7000 KB Output is correct
22 Correct 2 ms 7000 KB Output is correct
23 Correct 2 ms 7176 KB Output is correct
24 Correct 5 ms 7240 KB Output is correct
25 Correct 5 ms 7000 KB Output is correct
26 Correct 5 ms 7000 KB Output is correct
27 Correct 5 ms 7000 KB Output is correct
28 Correct 5 ms 7000 KB Output is correct
29 Correct 1 ms 7000 KB Output is correct
30 Correct 2 ms 7000 KB Output is correct
31 Correct 1 ms 7000 KB Output is correct
32 Correct 5 ms 7000 KB Output is correct
33 Correct 3 ms 7000 KB Output is correct
34 Correct 2 ms 7000 KB Output is correct
35 Correct 1 ms 7000 KB Output is correct
36 Correct 5 ms 7256 KB Output is correct
37 Correct 4 ms 7256 KB Output is correct
38 Correct 3 ms 7288 KB Output is correct
39 Correct 2 ms 7000 KB Output is correct
40 Correct 2 ms 7000 KB Output is correct
41 Correct 2 ms 7184 KB Output is correct
42 Correct 1 ms 7000 KB Output is correct
43 Correct 433 ms 7256 KB Output is correct
44 Correct 595 ms 7512 KB Output is correct
45 Correct 610 ms 7512 KB Output is correct
46 Correct 614 ms 7800 KB Output is correct
47 Correct 624 ms 7768 KB Output is correct
48 Correct 626 ms 7768 KB Output is correct
49 Correct 684 ms 7768 KB Output is correct
50 Correct 630 ms 7804 KB Output is correct
51 Correct 525 ms 7460 KB Output is correct
52 Correct 550 ms 7460 KB Output is correct
53 Correct 498 ms 7512 KB Output is correct
54 Correct 633 ms 8020 KB Output is correct
55 Correct 620 ms 7512 KB Output is correct
56 Correct 564 ms 7512 KB Output is correct
57 Correct 551 ms 7452 KB Output is correct
58 Correct 624 ms 8024 KB Output is correct
59 Correct 619 ms 8024 KB Output is correct
60 Correct 678 ms 8272 KB Output is correct
61 Correct 604 ms 7512 KB Output is correct
62 Correct 565 ms 7256 KB Output is correct
63 Correct 541 ms 7476 KB Output is correct
64 Correct 561 ms 7472 KB Output is correct
65 Correct 306 ms 7356 KB Output is correct
66 Correct 593 ms 7512 KB Output is correct
67 Correct 613 ms 7644 KB Output is correct
68 Correct 585 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7252 KB Output is correct
2 Correct 1 ms 7000 KB Output is correct
3 Correct 1 ms 7000 KB Output is correct
4 Correct 1 ms 7000 KB Output is correct
5 Correct 1 ms 7000 KB Output is correct
6 Correct 1 ms 7000 KB Output is correct
7 Correct 1 ms 7000 KB Output is correct
8 Correct 1 ms 7000 KB Output is correct
9 Correct 1 ms 7000 KB Output is correct
10 Correct 1 ms 7000 KB Output is correct
11 Correct 2 ms 7000 KB Output is correct
12 Correct 2 ms 7156 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
14 Correct 3 ms 7000 KB Output is correct
15 Correct 5 ms 7224 KB Output is correct
16 Correct 5 ms 7000 KB Output is correct
17 Correct 4 ms 7000 KB Output is correct
18 Correct 4 ms 7256 KB Output is correct
19 Correct 4 ms 7256 KB Output is correct
20 Correct 4 ms 7000 KB Output is correct
21 Correct 4 ms 7000 KB Output is correct
22 Correct 2 ms 7000 KB Output is correct
23 Correct 2 ms 7176 KB Output is correct
24 Correct 5 ms 7240 KB Output is correct
25 Correct 5 ms 7000 KB Output is correct
26 Correct 5 ms 7000 KB Output is correct
27 Correct 5 ms 7000 KB Output is correct
28 Correct 5 ms 7000 KB Output is correct
29 Correct 1 ms 7000 KB Output is correct
30 Correct 2 ms 7000 KB Output is correct
31 Correct 1 ms 7000 KB Output is correct
32 Correct 5 ms 7000 KB Output is correct
33 Correct 3 ms 7000 KB Output is correct
34 Correct 2 ms 7000 KB Output is correct
35 Correct 1 ms 7000 KB Output is correct
36 Correct 5 ms 7256 KB Output is correct
37 Correct 4 ms 7256 KB Output is correct
38 Correct 3 ms 7288 KB Output is correct
39 Correct 2 ms 7000 KB Output is correct
40 Correct 2 ms 7000 KB Output is correct
41 Correct 2 ms 7184 KB Output is correct
42 Correct 1 ms 7000 KB Output is correct
43 Execution timed out 3055 ms 11484 KB Time limit exceeded
44 Halted 0 ms 0 KB -