Submission #825525

# Submission time Handle Problem Language Result Execution time Memory
825525 2023-08-15T01:13:47 Z boyliguanhan Election (BOI18_election) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
struct Data {
    int l=0,r=0,s=0,a=0;
    Data(bool b) : l(b), r(b), s(b?1:-1), a(b){}
    Data(Data a, Data b) : l(max(a.l, a.s+b.l)), r(max(b.r,b.s+a.r)), s(a.s+b.s), a(max(max(a.a+b.s, b.a+a.s), a.l+b.r)){}
};
vector<vector<Data>> tb(500100, vector<Data>(20));
int main() {
    int n, q;
    string str;
    cin >> n >> str >> q;
    for(int i = 1; i <= n; i++) {
        tb[i][0] = Data(str[i-1]=='T');
    }
    for(int j = 1; j < 20; j++)
        for(int i = 1; i < n-(1<<j)+2; i++)
            tb[i][j] = Data(tb[i][j-1], tb[i+(1<<j-1)][j-1]);
    while(q--){
        Data d;
        int a, b;
        cin >> a >> b;
        for(int i = 20;i--;)
            if(a+(1<<i)-2<b)
                d = Data(d,tb[a][i]), a+=(1<<i);
        cout << d.a << '\n';
    }
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:18:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   18 |             tb[i][j] = Data(tb[i][j-1], tb[i+(1<<j-1)][j-1]);
      |                                                  ~^~
election.cpp:20:14: error: no matching function for call to 'Data::Data()'
   20 |         Data d;
      |              ^
election.cpp:6:5: note: candidate: 'Data::Data(Data, Data)'
    6 |     Data(Data a, Data b) : l(max(a.l, a.s+b.l)), r(max(b.r,b.s+a.r)), s(a.s+b.s), a(max(max(a.a+b.s, b.a+a.s), a.l+b.r)){}
      |     ^~~~
election.cpp:6:5: note:   candidate expects 2 arguments, 0 provided
election.cpp:5:5: note: candidate: 'Data::Data(bool)'
    5 |     Data(bool b) : l(b), r(b), s(b?1:-1), a(b){}
      |     ^~~~
election.cpp:5:5: note:   candidate expects 1 argument, 0 provided
election.cpp:3:8: note: candidate: 'constexpr Data::Data(const Data&)'
    3 | struct Data {
      |        ^~~~
election.cpp:3:8: note:   candidate expects 1 argument, 0 provided
election.cpp:3:8: note: candidate: 'constexpr Data::Data(Data&&)'
election.cpp:3:8: note:   candidate expects 1 argument, 0 provided
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/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from election.cpp:1:
/usr/include/c++/10/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = Data; _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 = Data*; _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 = Data*; _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 = Data*; _Size = long unsigned int; _Tp = Data]'
/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 = Data; _Alloc = std::allocator<Data>; 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 = Data; _Alloc = std::allocator<Data>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<Data>]'
election.cpp:8:48:   required from here
/usr/include/c++/10/bits/stl_construct.h:109:7: error: no matching function for call to 'Data::Data()'
  109 |     { ::new(static_cast<void*>(__p)) _Tp(std::forward<_Args>(__args)...); }
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:6:5: note: candidate: 'Data::Data(Data, Data)'
    6 |     Data(Data a, Data b) : l(max(a.l, a.s+b.l)), r(max(b.r,b.s+a.r)), s(a.s+b.s), a(max(max(a.a+b.s, b.a+a.s), a.l+b.r)){}
      |     ^~~~
election.cpp:6:5: note:   candidate expects 2 arguments, 0 provided
election.cpp:5:5: note: candidate: 'Data::Data(bool)'
    5 |     Data(bool b) : l(b), r(b), s(b?1:-1), a(b){}
      |     ^~~~
election.cpp:5:5: note:   candidate expects 1 argument, 0 provided
election.cpp:3:8: note: candidate: 'constexpr Data::Data(const Data&)'
    3 | struct Data {
      |        ^~~~
election.cpp:3:8: note:   candidate expects 1 argument, 0 provided
election.cpp:3:8: note: candidate: 'constexpr Data::Data(Data&&)'
election.cpp:3:8: note:   candidate expects 1 argument, 0 provided