QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657319#7904. Rainbow SubarrayDynamic_PigeonCompile Error//C++202.4kb2024-10-19 14:33:372024-10-19 14:33:42

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 14:33:42]
  • 评测
  • [2024-10-19 14:33:37]
  • 提交

answer

#include <bits/stdc++.h>
#include <iterator>

#ifdef DYNAMIC_PIGEON
#include "algo/debug.h"
#else
#define debug(...) 114514
#endif

#define Dynamic_Pigeon 0

using i64 = std::int64_t;
using u64 = std::uint64_t;
using u32 = std::uint32_t;

constexpr i64 MOD = i64(1e9) + 7;
constexpr int INF = 1e9;
constexpr i64 INF_LONG_LONG = 1e18;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()


struct Node {
  std::multiset<int> l, r;
  i64 pre = 0, lst = 0;

  int get_mid() {
    return *l.rbegin();
  }

  void insert(int x) {
    if (x > *l.rbegin()) {
      r.insert(x);
      lst += x;
    } else {
      l.insert(x);
      pre += x;
    }

    while (r.size() < l.size()) {
      lst += *l.rbegin();
      pre -= *l.rbegin();
      r.emplace(l.extract(std::prev(l.end())));
    }

    while (l.size() < r.size()) {
      lst -= *r.begin();
      pre += *r.begin();
      l.emplace(r.extract(r.begin()));
    }
  }

  void erase(int x) {
    if (x > *l.rbegin()) {
      lst -= x;
      r.extract(x);
    } else {
      pre -= x;
      l.extract(x);
    }

    while (r.size() < l.size()) {
      lst += *l.rbegin();
      pre -= *l.rbegin();
      r.emplace(l.extract(std::prev(l.end())));
    }

    while (l.size() < r.size()) {
      lst -= *r.begin();
      pre += *r.begin();
      l.emplace(r.extract(r.begin()));
    }
  } 
};


void tizzytyt_SuKi() {
  int n;
  i64 k;
  std::cin >> n >> k;
  std::vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    a[i] -= i;
  }

  a[0] = -INF;

  auto check = [&](int len) -> bool {
    Node m;
    for (int i = 1; i < len; i++) {
      m.insert(a[i]);
    }

    i64 res = INF_LONG_LONG;

    for (int i = len; i <= n; i++) {
      m.insert(a[i]);
      i64 mid = m.get_mid();
      i64 p = mid * i64(m.l.size()) - m.pre + m.lst - mid * i64(m.r.size());

      res = std::min(res, p);

      m.erase(a[i - len + 1]);
    }
    return res <= k;
  };

  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  std::cout << l << "\n";
}

signed main() {
#ifdef DYNAMIC_PIGEON
  freopen("input.in", "r", stdin);
#else
  std::cin.tie(0)->sync_with_stdio(0);
#endif
  int t = 1;
  std::cin >> t;
  while (t--) {
    tizzytyt_SuKi();
  }
  return Dynamic_Pigeon;
}

详细

In file included from /usr/include/c++/13/ext/alloc_traits.h:34,
                 from /usr/include/c++/13/bits/basic_string.h:39,
                 from /usr/include/c++/13/string:54,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:1:
/usr/include/c++/13/bits/alloc_traits.h: In instantiation of ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Tp = std::_Rb_tree_node<int>; allocator_type = std::allocator<std::_Rb_tree_node<int> >]’:
/usr/include/c++/13/bits/stl_tree.h:597:32:   required from ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(_Link_type, _Args&& ...) [with _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = std::allocator<int>; _Link_type = std::_Rb_tree_node<int>*]’
/usr/include/c++/13/bits/stl_tree.h:614:21:   required from ‘std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = std::allocator<int>; _Link_type = std::_Rb_tree_node<int>*]’
/usr/include/c++/13/bits/stl_tree.h:1637:32:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Auto_node::_Auto_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, _Args&& ...) [with _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = std::allocator<int>]’
/usr/include/c++/13/bits/stl_tree.h:2449:13:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_equal(_Args&& ...) [with _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::iterator]’
/usr/include/c++/13/bits/stl_multiset.h:460:32:   required from ‘std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::emplace(_Args&& ...) [with _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator]’
answer.code:44:16:   required from here
/usr/include/c++/13/bits/alloc_traits.h:539:28: error: no matching function for call to ‘construct_at(int*&, std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >)’
  539 |           std::construct_at(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/stl_iterator.h:85,
                 from /usr/include/c++/13/bits/stl_algobase.h:67,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51:
/usr/include/c++/13/bits/stl_construct.h:94:5: note: candidate: ‘template<class _Tp, class ... _Args> constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...)’
   94 |     construct_at(_Tp* __location, _Args&&... __args)
      |     ^~~~~~~~~~~~
/usr/include/c++/13/bits/stl_construct.h:94:5: note:   template argument deduction/substitution failed:
/usr/include/c++/13/bits/stl_construct.h: In substitution of ‘template<class _Tp, class ... _Args> constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = int; _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}]’:
/usr/include/c++/13/bits/alloc_traits.h:539:21:   required from ‘static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Tp = std::_Rb_tree_node<int>; allocator_type = std::allocator<std::_Rb_tree_node<int> >]’
/usr/include/c++/13/bits/stl_tree.h:597:32:   required from ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(_Link_type, _Args&& ...) [with _Args = {std::_Node_handle<int, int, std::allocator<std::_Rb_tree_node<int> > >}; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = std::allocator<int>; _Link_type = std::_Rb_tree_node<int>*]...