Submission #1024467

# Submission time Handle Problem Language Result Execution time Memory
1024467 2024-07-16T05:35:08 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
2 / 100
427 ms 18520 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};
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14680 KB Output is correct
4 Correct 10 ms 14680 KB Output is correct
5 Correct 10 ms 14908 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 10 ms 14680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Incorrect 3 ms 16728 KB 1st lines differ - on the 1st token, expected: '52130940', found: '844566252'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14680 KB Output is correct
4 Correct 10 ms 14680 KB Output is correct
5 Correct 10 ms 14908 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 10 ms 14680 KB Output is correct
9 Correct 3 ms 16728 KB Output is correct
10 Incorrect 3 ms 16728 KB 1st lines differ - on the 1st token, expected: '52130940', found: '844566252'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 427 ms 18520 KB 1st lines differ - on the 1st token, expected: '431985922', found: '37399904'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 427 ms 18520 KB 1st lines differ - on the 1st token, expected: '431985922', found: '37399904'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Incorrect 3 ms 16728 KB 1st lines differ - on the 1st token, expected: '52130940', found: '844566252'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14680 KB Output is correct
4 Correct 10 ms 14680 KB Output is correct
5 Correct 10 ms 14908 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 10 ms 14680 KB Output is correct
9 Correct 3 ms 16728 KB Output is correct
10 Incorrect 3 ms 16728 KB 1st lines differ - on the 1st token, expected: '52130940', found: '844566252'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16728 KB Output is correct
2 Correct 3 ms 16728 KB Output is correct
3 Correct 10 ms 14680 KB Output is correct
4 Correct 10 ms 14680 KB Output is correct
5 Correct 10 ms 14908 KB Output is correct
6 Correct 10 ms 14676 KB Output is correct
7 Correct 11 ms 14680 KB Output is correct
8 Correct 10 ms 14680 KB Output is correct
9 Correct 3 ms 16728 KB Output is correct
10 Incorrect 3 ms 16728 KB 1st lines differ - on the 1st token, expected: '52130940', found: '844566252'
11 Halted 0 ms 0 KB -