답안 #228644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228644 2020-05-02T08:43:04 Z DodgeBallMan 금 캐기 (IZhO14_divide) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
long long inf = 1e9;
long long n, t[N*4];
long long h[N], sum[N], gold[N], ans;
vector<long long> coord;

int get( int x ) { return upper_bound( coord.begin(), coord.end(), x ) - coord.begin(); }

void build( int l = 1, int r = coord.size(), int idx = 1 ) {
    t[idx] = inf;
    if( l == r ) return ;
    int mid = l + r >> 1;
    build( l, mid, idx<<1 ), build( mid+1, r, idx<<1|1 );
}

void update( int x, int va, int l = 1, int r = coord.size(), int idx = 1 ) {
    if( l > x || r < x ) return ;
    if( l == r ) return void( t[idx] = min( t[idx], va ) );
    int mid = l + r >> 1;
    update( x, va, l, mid, idx<<1 ), update( x, va, mid+1, r, idx<<1|1 );
    t[idx] = min( t[idx<<1], t[idx<<1|1] );
    return ;
}

long long query( int ll, int rr, int l = 1, int r = coord.size(), int idx = 1 ) {
    if( l > rr || r < ll ) return inf;
    if( l >= ll && r <= rr ) return t[idx];
    int mid = l + r >> 1;
    return min( query( ll, rr, l, mid, idx<<1 ), query( ll, rr, mid+1, r, idx<<1|1 ) );
}

int main()
{
    scanf("%lld",&n);
    for( int i = 1 ; i <= n ; i++ ) {
        scanf("%lld %lld %lld",&h[i],&gold[i],&sum[i]);
        sum[i] += sum[i-1], gold[i] += gold[i-1];
        coord.emplace_back( sum[i-1] - h[i] );
    }
    sort( coord.begin(), coord.end() );
    coord.resize( unique( coord.begin(), coord.end() ) - coord.begin() );
    build();
    /*for( long long i : coord ) printf("%lld ",i);
    printf("\n");*/
    for( int i = 1 ; i <= n ; i++ ) {
        int idx = get( sum[i] - h[i] ), idx2 = get( sum[i-1] - h[i] );
        update( idx2, i );
        ans = max( ans, gold[i] - gold[query( 1, idx ) - 1] );
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

divide.cpp: In function 'void build(int, int, int)':
divide.cpp:16:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
divide.cpp: In function 'void update(int, int, int, int, int)':
divide.cpp:22:56: error: no matching function for call to 'min(long long int&, int&)'
     if( l == r ) return void( t[idx] = min( t[idx], va ) );
                                                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from divide.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
divide.cpp:22:56: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     if( l == r ) return void( t[idx] = min( t[idx], va ) );
                                                        ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from divide.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
divide.cpp:22:56: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     if( l == r ) return void( t[idx] = min( t[idx], va ) );
                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from divide.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
divide.cpp:22:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     if( l == r ) return void( t[idx] = min( t[idx], va ) );
                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from divide.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
divide.cpp:22:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     if( l == r ) return void( t[idx] = min( t[idx], va ) );
                                                        ^
divide.cpp:22:58: error: return-statement with a value, in function returning 'void' [-fpermissive]
     if( l == r ) return void( t[idx] = min( t[idx], va ) );
                                                          ^
divide.cpp:23:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
divide.cpp: In function 'long long int query(int, int, int, int, int)':
divide.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
divide.cpp: In function 'int main()':
divide.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
divide.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %lld",&h[i],&gold[i],&sum[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~