Submission #797686

# Submission time Handle Problem Language Result Execution time Memory
797686 2023-07-29T18:48:18 Z jakobrs Digital Circuit (IOI22_circuit) C++17
4 / 100
711 ms 4672 KB
#include <iostream>
#include <vector>

using i64 = int64_t;

const i64 MOD = 1'000'002'022;

struct Node {
    i64 a1, ax;

    Node() : a1(0), ax(1) {}
    explicit Node(bool value) : a1(value), ax(1) {}
    Node(i64 a1, i64 ax) : a1(a1), ax(ax) {}

    Node operator*(const Node &rhs) const {
        return {(a1 * rhs.ax + ax * rhs.a1) % MOD, ax * rhs.ax * 2 % MOD};
    }
};

struct SegmentTree {
    std::vector<Node> values;
    i64 offset;

    SegmentTree() : values{}, offset{0} {}
    explicit SegmentTree(size_t sz) : values(2 * sz), offset(sz) {}

    void update(i64 idx, bool value) {
        idx += offset;

        values[idx] = Node(value);

        while (idx /= 2) {
            values[idx] = values[2 * idx] * values[2 * idx + 1];
        }
    }

    const Node &root() const { return values[1]; }
};

int n, m;
std::vector<int> p, a;

SegmentTree st;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N;
    m = M;
    p = P;
    a = A;

    st = SegmentTree(N + 1);

    for (i64 i = 0; i < M; i++) {
        st.update(i, A[i]);
    }
}

int count_ways(int l, int r) {
    r += 1;

    l -= n;
    r -= n;

    st.update(l, a[l] = !a[l]);

    return st.root().a1;
}

Compilation message

circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:64:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   64 |     st.update(l, a[l] = !a[l]);
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 515 ms 2496 KB Output is correct
2 Correct 567 ms 4656 KB Output is correct
3 Correct 711 ms 4628 KB Output is correct
4 Correct 642 ms 4672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 2496 KB Output is correct
2 Correct 567 ms 4656 KB Output is correct
3 Correct 711 ms 4628 KB Output is correct
4 Correct 642 ms 4672 KB Output is correct
5 Incorrect 580 ms 2376 KB 1st lines differ - on the 1st token, expected: '105182172', found: '2777846'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -