제출 #1204745

#제출 시각아이디문제언어결과실행 시간메모리
12047451binFloppy (RMI20_floppy)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h>
#include "floppy.h"

using namespace std;

typedef long long ll;
#define all(v) v.begin(), v.end()
//
// void save_to_floppy(string bits) {
//     cout << bits << endl;
//     return;
// }

void dfs(int x, vector<int> & L, vector<int>& R, string& bits) {
    if (x == -1) return;
    bits += (L[x] != -1) + '0';
    bits += (R[x] != -1) + '0';
    dfs(L[x], L, R, bits);
    dfs(R[x], L, R, bits);
}

void read_array(int subtask_id, const vector<int> &v) {
    int n = v.size(), x;
    vector<vector<int>> adj(n, vector<int>());
    vector<int> L(n, -1), R(n, -1);
    stack<int> st;

    string bits = "";
    for (int i = 0; i < n; i++) {
        while (st.size() && v[st.top()] < v[i]) {
            int j = st.top(); st.pop();
            if (st.empty() || v[st.top()] > v[i]) L[i] = j;
            else R[st.top()] = j;
        }
        st.emplace(i);
    }
    while (st.size()) {
        x = st.top(); st.pop();
        if (st.size()) R[st.top()] = x;
    }

    dfs(x, L, R, bits);
    save_to_floppy(bits);
}

const int B = 1 << 16;
int t, cur;
pair<int, int> seg[B * 2];
void find(string& bits, int v) {
    int tmp = t++;
    if (bits[tmp * 2] == '1') find(bits, v - 1);
    seg[B + cur] = {v, cur};
    cur++;
    if (bits[tmp * 2 + 1] == '1') find(bits, v - 1);
}

int Max(int l, int r) {
    l += B; r += B;
    pair<int, int> ret = {0, 0};
    while (l <= r) {
        if (l & 1) ret = max(ret, seg[l++]);
        if (!(r & 1)) ret = max(ret, seg[r--]);
        l >>= 1;r >>= 1;
    }
    return ret.second;
}

vector<int> solve_queries(int subtask_id, int N,
        const string &bits,
        const vector<int> &a, const std::vector<int> &b) {

    find(bits, N);
    vector<int> ans;
    for (int i = B - 1; i; i--) seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
    for (int i = 0; i < a.size(); i++) ans.emplace_back(Max(a[i], b[i]));
    return ans;
}

// int main(void) {
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//
//     // vector<int> v = {40, 20, 30, 10};
//     // read_array(0, v);
//
//     string bits = "01110000";
//     vector<int> a = {0, 0, 0, 0, 1, 1, 1, 2, 2, 3};
//     vector<int> b = {0, 1, 2, 3, 1, 2, 3, 2, 3, 3};
//
//     for (int& x : solve_queries(0, 4, bits, a, b)) cout << x << ' ';
//     return 0;
// }

컴파일 시 표준 에러 (stderr) 메시지

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:72:9: error: no matching function for call to 'find(const string&, int&)'
   72 |     find(bits, N);
      |     ~~~~^~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from floppy.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3876:5: note: candidate: 'template<class _IIter, class _Tp> constexpr _IIter std::find(_IIter, _IIter, const _Tp&)'
 3876 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/11/bits/stl_algo.h:3876:5: note:   template argument deduction/substitution failed:
floppy.cpp:72:9: note:   deduced conflicting types for parameter '_IIter' ('std::__cxx11::basic_string<char>' and 'int')
   72 |     find(bits, N);
      |     ~~~~^~~~~~~~~
In file included from /usr/include/c++/11/bits/locale_facets.h:48,
                 from /usr/include/c++/11/bits/basic_ios.h:37,
                 from /usr/include/c++/11/ios:44,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from floppy.cpp:1:
/usr/include/c++/11/bits/streambuf_iterator.h:421:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >, const _CharT2&)'
  421 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/11/bits/streambuf_iterator.h:421:5: note:   template argument deduction/substitution failed:
floppy.cpp:72:9: note:   'std::__cxx11::basic_string<char>' is not derived from 'std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >'
   72 |     find(bits, N);
      |     ~~~~^~~~~~~~~
In file included from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from floppy.cpp:1:
/usr/include/c++/11/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/11/pstl/glue_algorithm_defs.h:60:1: note:   template argument deduction/substitution failed:
floppy.cpp:72:9: note:   candidate expects 4 arguments, 2 provided
   72 |     find(bits, N);
      |     ~~~~^~~~~~~~~
floppy.cpp:49:6: note: candidate: 'void find(std::string&, int)' (near match)
   49 | void find(string& bits, int v) {
      |      ^~~~
floppy.cpp:49:6: note:   conversion of argument 1 would be ill-formed:
floppy.cpp:72:10: error: binding reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to 'const string' {aka 'const std::__cxx11::basic_string<char>'} discards qualifiers
   72 |     find(bits, N);
      |          ^~~~