답안 #263257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263257 2020-08-13T14:44:20 Z alexandra_udristoiu Building Bridges (CEOI17_building) C++14
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<algorithm>
#define DIM 100005
#define x first
#define y second
using namespace std;
int n, i, m;
int h[DIM], w[DIM], a[DIM];
pair<long long, long long> aint[4 * DIM], p[DIM];
long long sum, d[DIM];
long long calc(pair<int, int> p, int i){
    return p.x * 1LL * i + p.y;
}
void build(int nod, int st, int dr){
    aint[nod] = p[1];
    if(st != dr){
        int mid = (st + dr) / 2;
        build(2 * nod, st, mid);
        build(2 * nod + 1, mid + 1, dr);
    }
}
void update(int nod, int st, int dr, pair<int, int> p){
    int mid = (st + dr) / 2;
    if( calc(aint[nod], a[mid]) > calc(p, a[mid]) ){
        swap(aint[nod], p);
    }
    if(st != dr){
        if( calc(aint[nod], a[st]) < calc(p, a[st]) ){
            update(2 * nod + 1, mid + 1, dr, p);
        }
        else{
            update(2 * nod, st, mid, p);
        }
    }
}
long long query(int nod, int st, int dr, int p){
    if(st == dr){
        return calc(aint[nod], p);
    }
    else{
        int mid = (st + dr) / 2;
        long long x;
        if(p <= a[mid]){
            x = query(2 * nod, st, mid, p);
        }
        else{
            x = query(2 * nod + 1, mid + 1, dr, p);
        }
        return min(x, calc(aint[nod], p) );
    }
}
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> h[i];
        a[i] = h[i];
    }
    sort(a + 1, a + n + 1);
    for(i = 1; i <= n; i++){
        cin>> w[i];
        m = max(m, h[i]);
        sum += w[i];
        p[i].y = h[i] * 1LL * h[i] - w[i];
        p[i].x = -2 * h[i];
    }
    build(1, 1, n);
    for(i = 2; i <= n; i++){
        d[i] = query(1, 1, n, h[i]) - w[i] + h[i] * 1LL * h[i];
        p[i].y = d[i] + h[i] * 1LL * h[i];
        update(1, 1, n, p[i]);
    }
    cout<< d[n] + sum;
}

Compilation message

building.cpp: In function 'void update(int, int, int, std::pair<int, int>)':
building.cpp:25:26: error: no matching function for call to 'swap(std::pair<long long int, long long int>&, std::pair<int, int>&)'
   25 |         swap(aint[nod], p);
      |                          ^
In file included from /usr/include/c++/9/bits/nested_exception.h:40,
                 from /usr/include/c++/9/exception:144,
                 from /usr/include/c++/9/ios:39,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from building.cpp:1:
/usr/include/c++/9/bits/move.h:182:5: note: candidate: 'template<class _Tp> typename std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)'
  182 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/9/bits/move.h:182:5: note:   template argument deduction/substitution failed:
building.cpp:25:26: note:   deduced conflicting types for parameter '_Tp' ('std::pair<long long int, long long int>' and 'std::pair<int, int>')
   25 |         swap(aint[nod], p);
      |                          ^
In file included from /usr/include/c++/9/bits/nested_exception.h:40,
                 from /usr/include/c++/9/exception:144,
                 from /usr/include/c++/9/ios:39,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from building.cpp:1:
/usr/include/c++/9/bits/move.h:205:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  205 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/9/bits/move.h:205:5: note:   template argument deduction/substitution failed:
building.cpp:25:26: note:   mismatched types '_Tp [_Nm]' and 'std::pair<long long int, long long int>'
   25 |         swap(aint[nod], p);
      |                          ^
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from building.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:495:5: note: candidate: 'template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)'
  495 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/9/bits/stl_pair.h:495:5: note:   template argument deduction/substitution failed:
building.cpp:25:26: note:   deduced conflicting types for parameter '_T1' ('long long int' and 'int')
   25 |         swap(aint[nod], p);
      |                          ^
In file included from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from building.cpp:1:
/usr/include/c++/9/bits/basic_string.h:6378:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6378 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/9/bits/basic_string.h:6378:5: note:   template argument deduction/substitution failed:
building.cpp:25:26: note:   'std::pair<long long int, long long int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   25 |         swap(aint[nod], p);
      |                          ^