제출 #619277

#제출 시각아이디문제언어결과실행 시간메모리
619277Sergio_2357커다란 상품 (IOI17_prize)C++17
컴파일 에러
0 ms0 KiB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

struct SegTree {
    int n;
    vi v;
    void update(int i, int val)
    {
        int p = i + n;
        v[p] = val;
        while (p /= 2)
            v[p] = v[2 * p] + v[2 * p + 1];
    }
    int query(int i, int l, int h, int ql, int qh)
    {
        if (h <= ql || qh <= l)
            return 0;
        if (l <= ql && qh <= h)
            return v[i];
        int m = (h - l) / 2 + l;
        return query(2 * i, l, m, ql, qh) + query(2 * i + 1, m, h, ql, qh);
    }
    int query(int l, int h)
    {
        return query(1, 0, n, l, h);
    }
    SegTree() { }
    SegTree(int sz)
    {
        n = 1;
        while (n < sz)
            n *= 2;
        v = vi(2 * n + 1, 0);
    }
};

int n;
SegTree st;
set<int> nl;
map<int, vi> qr;
int llc = 0;
int res = -1;

vi ask2(int i)
{
    if (qr.count(i))
        return qr[i];
    qr[i] = ask(i);
    return qr[i];
}

int cask(int i)
{
    while (nl.count(i))
        i++;
    if (i >= n)
        i--;
    while (nl.count(i))
        i--;
    auto p = ask2(i);
    if (p[0] + p[1] == 0)
        res = i;
    if (p[0] + p[1] < llc) {
        if (nl.count() != st.query(0, n))
            res = -2;
        nl.insert(i);
        st.update(i, 1);
        return 2;
    }
    int l = p[0] - st.query(0, i);
    int r = p[1] - st.query(i, n);
    return l < r;
}

int find_best(int n_)
{
    n = n_;
    st = SegTree(n + 1);
    for (int i = 0; i < min(n, 500); i++) {
        auto p = ask2(i);
        llc = max(llc, p[0] + p[1]);
        if (p[0] + p[1] == 0)
            return i;
    }
    int marp = 100000;
    while (res == -1 && marp--) {
        int l = 0;
        int h = n - 1;
        bool found = false;
        while (l < h - 2) {
            int m = (h - l) / 2 + l;
            int r = cask(m);
            if (r == 2) {
                found = true;
                break;
            }
            if (!r)
                h = m;
            else
                l = m;
        }
        if (!found)
            for (int i = l; i <= h; i++)
                cask(i);
    }
    return res;
}

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

prize.cpp: In function 'int cask(int)':
prize.cpp:68:22: error: no matching function for call to 'std::set<int>::count()'
   68 |         if (nl.count() != st.query(0, n))
      |                      ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from prize.cpp:2:
/usr/include/c++/10/bits/stl_set.h:748:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = int]'
  748 |       count(const key_type& __x) const
      |       ^~~~~
/usr/include/c++/10/bits/stl_set.h:748:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/10/bits/stl_set.h:754:2: note: candidate: 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = _Kt; _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  754 |  count(const _Kt& __x) const
      |  ^~~~~
/usr/include/c++/10/bits/stl_set.h:754:2: note:   template argument deduction/substitution failed:
prize.cpp:68:22: note:   candidate expects 1 argument, 0 provided
   68 |         if (nl.count() != st.query(0, n))
      |                      ^