답안 #797685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797685 2023-07-29T18:47:07 Z jakobrs 디지털 회로 (IOI22_circuit) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>

using i64 = int64_t;

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

struct Node {
    i64 a1, ax;

    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;

    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:41:13: error: no matching function for call to 'SegmentTree::SegmentTree()'
   41 | SegmentTree st;
      |             ^~
circuit.cpp:23:14: note: candidate: 'SegmentTree::SegmentTree(size_t)'
   23 |     explicit SegmentTree(size_t sz) : values(2 * sz), offset(sz) {}
      |              ^~~~~~~~~~~
circuit.cpp:23:14: note:   candidate expects 1 argument, 0 provided
circuit.cpp:19:8: note: candidate: 'SegmentTree::SegmentTree(const SegmentTree&)'
   19 | struct SegmentTree {
      |        ^~~~~~~~~~~
circuit.cpp:19:8: note:   candidate expects 1 argument, 0 provided
circuit.cpp:19:8: note: candidate: 'SegmentTree::SegmentTree(SegmentTree&&)'
circuit.cpp:19:8: note:   candidate expects 1 argument, 0 provided
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:62:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   62 |     st.update(l, a[l] = !a[l]);
In file included from /usr/include/c++/10/bits/alloc_traits.h:33,
                 from /usr/include/c++/10/ext/alloc_traits.h:34,
                 from /usr/include/c++/10/bits/basic_string.h:40,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = Node; _Args = {}]':
/usr/include/c++/10/bits/stl_uninitialized.h:567:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Node*; _Size = long unsigned int; bool _TrivialValueType = false]'
/usr/include/c++/10/bits/stl_uninitialized.h:623:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = Node*; _Size = long unsigned int]'
/usr/include/c++/10/bits/stl_uninitialized.h:685:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = Node*; _Size = long unsigned int; _Tp = Node]'
/usr/include/c++/10/bits/stl_vector.h:1606:36:   required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = Node; _Alloc = std::allocator<Node>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
/usr/include/c++/10/bits/stl_vector.h:512:9:   required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = Node; _Alloc = std::allocator<Node>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<Node>]'
circuit.cpp:23:64:   required from here
/usr/include/c++/10/bits/stl_construct.h:109:7: error: no matching function for call to 'Node::Node()'
  109 |     { ::new(static_cast<void*>(__p)) _Tp(std::forward<_Args>(__args)...); }
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circuit.cpp:12:5: note: candidate: 'Node::Node(i64, i64)'
   12 |     Node(i64 a1, i64 ax) : a1(a1), ax(ax) {}
      |     ^~~~
circuit.cpp:12:5: note:   candidate expects 2 arguments, 0 provided
circuit.cpp:11:14: note: candidate: 'Node::Node(bool)'
   11 |     explicit Node(bool value) : a1(value), ax(1) {}
      |              ^~~~
circuit.cpp:11:14: note:   candidate expects 1 argument, 0 provided
circuit.cpp:8:8: note: candidate: 'constexpr Node::Node(const Node&)'
    8 | struct Node {
      |        ^~~~
circuit.cpp:8:8: note:   candidate expects 1 argument, 0 provided
circuit.cpp:8:8: note: candidate: 'constexpr Node::Node(Node&&)'
circuit.cpp:8:8: note:   candidate expects 1 argument, 0 provided