답안 #1024470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024470 2024-07-16T05:39:29 Z vjudge1 디지털 회로 (IOI22_circuit) C++17
34 / 100
3000 ms 24144 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define s second 
#define f first 

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 5e5, mod = 1000002022;

int n, m, is = 1;
vector<int> g[N], a(N);

pii t[4 * N];
int swp[4 * N];

pii f(pii x, pii y) {
    ll val[3];
    val[0] = (x.s * 1ll * y.s) % mod;
    val[1] = ((x.f * 1ll * y.s) + (x.s * 1ll * y.f)) % mod;
    val[2] = (x.f * 1ll * y.f) % mod;
    pii v;
    v.f = (val[1] + val[2] * 2) % mod;
    v.s = (val[1] + val[0] * 2) % mod;
    return v;
}

void bld(int u = 1, int tl = 0, int tr = m - 1) {
    if (tl == tr) {
        if (a[tl + n]) t[u] = {1, 0};
        else t[u] = {0, 1};
        return;
    }
    int mid = (tl + tr) / 2;
    bld(u * 2, tl, mid);
    bld(u * 2 + 1, mid + 1, tr);
    t[u] = f(t[u * 2], t[u * 2 + 1]);
}

void push(int u, int tl, int tr) {
    if (!swp[u]) return;
    swap(t[u].f, t[u].s);
    if (tl < tr) {
        swp[u * 2] ^= 1;
        swp[u * 2 + 1] ^= 1;
    }
    swp[u] = 0;
}

void upd(int l, int r, int u = 1, int tl = 0, int tr = m - 1) {
    push(u, tl, tr);
    if (tl > r || tr < l) return;
    if (tl >= l && tr <= r) {
        swp[u] = 1;
        push(u, tl, tr);
        return;
    }
    int mid = (tl + tr) / 2;
    upd(l, r, u * 2, tl, mid);
    upd(l, r, u * 2 + 1, mid + 1, tr);
    t[u] = f(t[u * 2], t[u * 2 + 1]);
}

void init(int nn, int M, vector<int> P, vector<int> A) {
    n = nn, m = M;
    for (int i = 0; i < m; i++) a[i + n] = A[i];
    for (int i = 1; i < n + m; i++) {
        if (P[i] != (i - 1) / 2) is = 0;
        g[P[i]].push_back(i);
    }
    if (__builtin_popcount(m) > 1) is = 0;
    if (is) bld();
}

pii get(int u) {
    if (!sz(g[u])) {
        if (a[u]) return {1, 0};
        return {0, 1};
    }
    int cnt = 0;
    vector<ll> val(sz(g[u]) + 1);
    val[0] = 1;
    for (int to: g[u]) {
        cnt++;
        auto [x, y] = get(to);
        for (int i = cnt; i >= 0; i--) {
            val[i] = (val[i] * y) % mod;
            if (i) val[i] = (val[i] + val[i - 1] * x) % mod;
        }
    }
    ll x = 0, y = 0;
    for (int i = 0; i <= cnt; i++) {
        x = (x + val[i] * i) % mod;
        y = (y + val[i] * (cnt - i)) % mod;
    }
    return {x, y};
}

int count_ways(int l, int r) {
    if (is) {
        upd(l - n, r - n);
        return t[1].f;
    }
    for (int i = l; i <= r; i++) {
        a[i] = 1 - a[i];
    }
    return get(0).f;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14908 KB Output is correct
4 Correct 11 ms 14680 KB Output is correct
5 Correct 11 ms 14680 KB Output is correct
6 Correct 10 ms 14780 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 11 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 4 ms 16728 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 4 ms 16728 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 3 ms 14680 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14908 KB Output is correct
4 Correct 11 ms 14680 KB Output is correct
5 Correct 11 ms 14680 KB Output is correct
6 Correct 10 ms 14780 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 11 ms 14680 KB Output is correct
9 Correct 3 ms 16728 KB Output is correct
10 Correct 4 ms 16728 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 4 ms 16728 KB Output is correct
13 Correct 3 ms 16728 KB Output is correct
14 Correct 3 ms 14680 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 3 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14680 KB Output is correct
21 Correct 3 ms 14680 KB Output is correct
22 Correct 3 ms 14876 KB Output is correct
23 Correct 3 ms 14680 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14936 KB Output is correct
26 Correct 4 ms 14936 KB Output is correct
27 Correct 3 ms 14896 KB Output is correct
28 Correct 3 ms 14936 KB Output is correct
29 Correct 11 ms 14680 KB Output is correct
30 Correct 10 ms 14680 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 3 ms 14936 KB Output is correct
33 Correct 3 ms 14680 KB Output is correct
34 Correct 3 ms 14680 KB Output is correct
35 Correct 5 ms 14680 KB Output is correct
36 Correct 3 ms 14936 KB Output is correct
37 Correct 11 ms 14936 KB Output is correct
38 Correct 12 ms 14936 KB Output is correct
39 Correct 3 ms 14768 KB Output is correct
40 Correct 3 ms 14680 KB Output is correct
41 Correct 3 ms 14680 KB Output is correct
42 Correct 4 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 18512 KB Output is correct
2 Correct 697 ms 22360 KB Output is correct
3 Correct 716 ms 22356 KB Output is correct
4 Correct 655 ms 22360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 18512 KB Output is correct
2 Correct 697 ms 22360 KB Output is correct
3 Correct 716 ms 22356 KB Output is correct
4 Correct 655 ms 22360 KB Output is correct
5 Correct 533 ms 20564 KB Output is correct
6 Correct 694 ms 24144 KB Output is correct
7 Correct 724 ms 22568 KB Output is correct
8 Correct 709 ms 22352 KB Output is correct
9 Correct 336 ms 16984 KB Output is correct
10 Correct 711 ms 16984 KB Output is correct
11 Correct 682 ms 16984 KB Output is correct
12 Correct 649 ms 16984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 4 ms 16728 KB Output is correct
3 Correct 4 ms 16728 KB Output is correct
4 Correct 4 ms 16728 KB Output is correct
5 Correct 3 ms 16728 KB Output is correct
6 Correct 3 ms 14680 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14680 KB Output is correct
13 Correct 476 ms 18512 KB Output is correct
14 Correct 697 ms 22360 KB Output is correct
15 Correct 716 ms 22356 KB Output is correct
16 Correct 655 ms 22360 KB Output is correct
17 Correct 533 ms 20564 KB Output is correct
18 Correct 694 ms 24144 KB Output is correct
19 Correct 724 ms 22568 KB Output is correct
20 Correct 709 ms 22352 KB Output is correct
21 Correct 336 ms 16984 KB Output is correct
22 Correct 711 ms 16984 KB Output is correct
23 Correct 682 ms 16984 KB Output is correct
24 Correct 649 ms 16984 KB Output is correct
25 Execution timed out 3014 ms 20108 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14908 KB Output is correct
4 Correct 11 ms 14680 KB Output is correct
5 Correct 11 ms 14680 KB Output is correct
6 Correct 10 ms 14780 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 11 ms 14680 KB Output is correct
9 Correct 3 ms 16728 KB Output is correct
10 Correct 4 ms 16728 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 4 ms 16728 KB Output is correct
13 Correct 3 ms 16728 KB Output is correct
14 Correct 3 ms 14680 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 3 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14680 KB Output is correct
21 Correct 3 ms 14680 KB Output is correct
22 Correct 3 ms 14876 KB Output is correct
23 Correct 3 ms 14680 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14936 KB Output is correct
26 Correct 4 ms 14936 KB Output is correct
27 Correct 3 ms 14896 KB Output is correct
28 Correct 3 ms 14936 KB Output is correct
29 Correct 11 ms 14680 KB Output is correct
30 Correct 10 ms 14680 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 3 ms 14936 KB Output is correct
33 Correct 3 ms 14680 KB Output is correct
34 Correct 3 ms 14680 KB Output is correct
35 Correct 5 ms 14680 KB Output is correct
36 Correct 3 ms 14936 KB Output is correct
37 Correct 11 ms 14936 KB Output is correct
38 Correct 12 ms 14936 KB Output is correct
39 Correct 3 ms 14768 KB Output is correct
40 Correct 3 ms 14680 KB Output is correct
41 Correct 3 ms 14680 KB Output is correct
42 Correct 4 ms 14676 KB Output is correct
43 Execution timed out 3008 ms 14936 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14908 KB Output is correct
4 Correct 11 ms 14680 KB Output is correct
5 Correct 11 ms 14680 KB Output is correct
6 Correct 10 ms 14780 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 11 ms 14680 KB Output is correct
9 Correct 3 ms 16728 KB Output is correct
10 Correct 4 ms 16728 KB Output is correct
11 Correct 4 ms 16728 KB Output is correct
12 Correct 4 ms 16728 KB Output is correct
13 Correct 3 ms 16728 KB Output is correct
14 Correct 3 ms 14680 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 3 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14680 KB Output is correct
21 Correct 3 ms 14680 KB Output is correct
22 Correct 3 ms 14876 KB Output is correct
23 Correct 3 ms 14680 KB Output is correct
24 Correct 3 ms 14936 KB Output is correct
25 Correct 3 ms 14936 KB Output is correct
26 Correct 4 ms 14936 KB Output is correct
27 Correct 3 ms 14896 KB Output is correct
28 Correct 3 ms 14936 KB Output is correct
29 Correct 11 ms 14680 KB Output is correct
30 Correct 10 ms 14680 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 3 ms 14936 KB Output is correct
33 Correct 3 ms 14680 KB Output is correct
34 Correct 3 ms 14680 KB Output is correct
35 Correct 5 ms 14680 KB Output is correct
36 Correct 3 ms 14936 KB Output is correct
37 Correct 11 ms 14936 KB Output is correct
38 Correct 12 ms 14936 KB Output is correct
39 Correct 3 ms 14768 KB Output is correct
40 Correct 3 ms 14680 KB Output is correct
41 Correct 3 ms 14680 KB Output is correct
42 Correct 4 ms 14676 KB Output is correct
43 Correct 476 ms 18512 KB Output is correct
44 Correct 697 ms 22360 KB Output is correct
45 Correct 716 ms 22356 KB Output is correct
46 Correct 655 ms 22360 KB Output is correct
47 Correct 533 ms 20564 KB Output is correct
48 Correct 694 ms 24144 KB Output is correct
49 Correct 724 ms 22568 KB Output is correct
50 Correct 709 ms 22352 KB Output is correct
51 Correct 336 ms 16984 KB Output is correct
52 Correct 711 ms 16984 KB Output is correct
53 Correct 682 ms 16984 KB Output is correct
54 Correct 649 ms 16984 KB Output is correct
55 Execution timed out 3014 ms 20108 KB Time limit exceeded
56 Halted 0 ms 0 KB -