Submission #1134657

#TimeUsernameProblemLanguageResultExecution timeMemory
1134657ten_xd트리 (IOI24_tree)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back
#include "tree.h"

const int N = 1e5+5432, INF = 2e9+54321;
const ll INF_L = (ll)2e18+54321;

struct Element
{
  ll val,su;
  bool operator < (const Element &element) const
  {
    return val < element.val;
  }
};

ll n,q,l,r,res;
vector<ll> G[N];
multiset<Element> us[N];
ll su_us[N], C[N];

std::vector<int> p, w;

void DFS(int v)
{
  su_us[v] = 0, us[v].clear(), C[v] = 0;
  for(auto x : G[v])
  {
    if(x == P[v]) continue;
    DFS(x);
    su_us[v] += su_us[x], C[v] += C[x];
    for(auto it = us[x].begin(); it != us[x].end(); ++it) us[v].insert(*it);
  }
  if(C[v] == 0)
  {
    C[v] = l, res += C[v]*abs(W[v]);
  }
  else
  {
    us[v].insert({W[v],(ll)2e6}), su_us[v] += (ll)2e6;
    while(C[v] > r)
    {
      ll roz = C[v]-r;
      Element at = *us[v].begin();
      us[v].erase(us[v].find(at));
      if(at.su <= roz)
      {
        C[v] -= at.su, su_us[v] -= at.su, res += at.val*at.su;
      }
      else
      {
        C[v] -= roz, su_us[v] -= roz, res += at.val*roz;
        us[v].insert({at.val,at.su-roz});
      }
    }
    while(su_us[v] > C[v]-l)
    {
      ll roz = su_us[v]-(C[v]-l);
      Element at = *us[v].rbegin();
      us[v].erase(us[v].find(at));
      if(at.su <= roz)
      {
        su_us[v] -= at.su;
      }
      else
      {
        su_us[v] -= roz, us[v].insert({at.val,at.su-roz});
      }
    }
  }
}

void init(std::vector<int> P, std::vector<int> W) {
  p = P;
  w = W;
  n = (int)p.size();

  for(int i = 1; i < n; ++i)
  {
    G[p[i]].pb(i);
  }
}

long long query(int L, int R) {
  res = 0, l = L, r = R;
  DFS(0);

  return res;
}

Compilation message (stderr)

tree.cpp: In function 'void DFS(int)':
tree.cpp:34:13: error: 'P' was not declared in this scope
   34 |     if(x == P[v]) continue;
      |             ^
tree.cpp:41:31: error: 'W' was not declared in this scope
   41 |     C[v] = l, res += C[v]*abs(W[v]);
      |                               ^
tree.cpp:45:19: error: 'W' was not declared in this scope
   45 |     us[v].insert({W[v],(ll)2e6}), su_us[v] += (ll)2e6;
      |                   ^
tree.cpp:45:17: error: no matching function for call to 'std::multiset<Element>::insert(<brace-enclosed initializer list>)'
   45 |     us[v].insert({W[v],(ll)2e6}), su_us[v] += (ll)2e6;
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87,
                 from tree.cpp:1:
/usr/include/c++/11/bits/stl_multiset.h:551:9: note: candidate: 'template<class _InputIterator> void std::multiset<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>]'
  551 |         insert(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:551:9: note:   template argument deduction/substitution failed:
tree.cpp:45:17: note:   candidate expects 2 arguments, 1 provided
   45 |     us[v].insert({W[v],(ll)2e6}), su_us[v] += (ll)2e6;
      |     ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/set:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:87,
                 from tree.cpp:1:
/usr/include/c++/11/bits/stl_multiset.h:502:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::value_type = Element]'
  502 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:502:32: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const Element&'}
  502 |       insert(const value_type& __x)
      |              ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_multiset.h:507:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::value_type = Element]'
  507 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:507:27: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::multiset<Element>::value_type&&' {aka 'Element&&'}
  507 |       insert(value_type&& __x)
      |              ~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_multiset.h:532:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::value_type = Element]'
  532 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:532:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_multiset.h:537:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::value_type&&) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::value_type = Element]'
  537 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:537:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/11/bits/stl_multiset.h:563:7: note: candidate: 'void std::multiset<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>]'
  563 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:563:43: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<Element>'
  563 |       insert(initializer_list<value_type> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_multiset.h:583:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::node_type&&) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::node_type]'
  583 |       insert(node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:583:26: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::multiset<Element>::node_type&&' {aka 'std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::node_type&&'}
  583 |       insert(node_type&& __nh)
      |              ~~~~~~~~~~~~^~~~
/usr/include/c++/11/bits/stl_multiset.h:588:7: note: candidate: 'std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::insert(std::multiset<_Key, _Compare, _Alloc>::const_iterator, std::multiset<_Key, _Compare, _Alloc>::node_type&&) [with _Key = Element; _Compare = std::less<Element>; _Alloc = std::allocator<Element>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::const_iterator; std::multiset<_Key, _Compare, _Alloc>::node_type = std::_Rb_tree<Element, Element, std::_Identity<Element>, std::less<Element>, std::allocator<Element> >::node_type]'
  588 |       insert(const_iterator __hint, node_type&& __nh)
      |       ^~~~~~
/usr/include/c++/11/bits/stl_multiset.h:588:7: note:   candidate expects 2 arguments, 1 provided