Submission #1245990

#TimeUsernameProblemLanguageResultExecution timeMemory
1245990LittleOrange나일강 (IOI24_nile)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll big = 1e18;
struct dsu{
    ll n,ans;
    vector<ll> p,sm,cls;
    array<vector<ll>,2> mi;
    dsu(const vector<ll> &a):n(a.size()),ans(0),p(a.size(),-1),sm(a){
        cls.resize(n);
        iota(cls.begin(),cls.end());
        mi[0].assign(n,big);
        mi[1].assign(n,big);
        for(ll i = 0;i<n;i++){
            mi[i&1] = a[i];
        }
    }
    ll g(ll i){
        return p[i]<0?i:p[i]=g(p[i]);
    }
    ll cal(ll i){
        return sm[i]-(p[i]&1)*mi[cls[i]&1][i];
    }
    void m(ll a, ll b){
        a = g(a),b = g(b);
        if(a==b)return;
        ans -= cal(a)+cal(b);
        if(p[a]>p[b]) swap(a,b);
        sm[a] += sm[b];
        mi[0][a] = min(mi[0][a],mi[0][b]);
        mi[1][a] = min(mi[1][a],mi[1][b]);
        cls[a] = min(cls[a],cls[b]);
        p[a] += p[b];
        p[b] = a;
        ans += cal(a);
    }
    void upd(ll i, ll v){
        ll typ = i&1;
        i = g(i);
        ans -= cal(i);
        mi[typ^1][i] = min(mi[typ^1][i],v);
        ans += cal(i);
    }
};
vector<long long> calculate_costs(vector<int> w, vector<int> a, vector<int> b, vector<int> e){
    ll n = w.size();
    ll q = e.size();
    ll tot = 0;
    for(ll i : a) tot += i;
    vector<pair<ll,ll>> v;
    for(ll i = 0;i<n;i++) v.push_back({w[i],a[i]-b[i]});
    sort(v.begin(),v.end());
    vector<ll> h(n);
    for(ll i = 0;i<n;i++) h[i] = v[i].second;
    dsu d(h);
    vector<pair<ll,ll>> u;
    for(ll i = 0;i<n-1;i++) u.push_back({v[i+1].first-v[i].first,i});
    for(ll i = 0;i<n-2;i++) u.push_back({v[i+2].first-v[i].first,-(i+1)});
    sort(u.begin(),u.end());
    vector<pair<ll,ll>> o;
    o.push_back({0,0});
    for(auto [dd,i] : u){
        if(i<0){
            d.upd(-i,h[-i]);
        }else{
            d.m(i,i+1);
        }
        o.push_back({dd,d.ans});
    }
    vector<ll> ret(q);
    for(ll i = 0;i<q;i++){
        ret[i] = tot-(*--lower_bound(o.begin(),o.end(),pair<ll,ll>((ll)e[i]+1,0ll))).second;
    }
    return ret;
}

Compilation message (stderr)

nile.cpp: In constructor 'dsu::dsu(const std::vector<long long int>&)':
nile.cpp:11:13: error: no matching function for call to 'iota(std::vector<long long int>::iterator, std::vector<long long int>::iterator)'
   11 |         iota(cls.begin(),cls.end());
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:84,
                 from nile.cpp:1:
/usr/include/c++/11/bits/stl_numeric.h:88:5: note: candidate: 'template<class _ForwardIterator, class _Tp> constexpr void std::iota(_ForwardIterator, _ForwardIterator, _Tp)'
   88 |     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
      |     ^~~~
/usr/include/c++/11/bits/stl_numeric.h:88:5: note:   template argument deduction/substitution failed:
nile.cpp:11:13: note:   candidate expects 3 arguments, 2 provided
   11 |         iota(cls.begin(),cls.end());
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~
nile.cpp:15:26: error: no match for 'operator=' (operand types are 'std::array<std::vector<long long int>, 2>::value_type' {aka 'std::vector<long long int>'} and 'const value_type' {aka 'const long long int'})
   15 |             mi[i&1] = a[i];
      |                          ^
In file included from /usr/include/c++/11/vector:72,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from nile.cpp:1:
/usr/include/c++/11/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'const value_type' {aka 'const long long int'} to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from nile.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'const value_type' {aka 'const long long int'} to 'std::vector<long long int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'const value_type' {aka 'const long long int'} to 'std::initializer_list<long long int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~