답안 #989415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989415 2024-05-28T06:43:08 Z HuyAT Sjeckanje (COCI21_sjeckanje) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#define newl '\n'

const int N = 2e5 + 10;
const int V = 1e7 + 10;
const long long INF = 1e18;
const long long M = 1e9 + 7;

long long a[N + 1],n,q;
long long diff[N + 1],f[N + 1];

void readData(){
    std::cin >> n >> q;
    for(int i = 1;i <= n;++i){
        std::cin >> a[i];
        if(i > 1){
            diff[i - 1] = a[i] - a[i - 1];
        }
    }
}
long long calc(){
    for(int i = 1;i <= n;++i){
        f[i] = 0;
        int mx = a[i],mn = a[i];
        for(int j = i;j >= 1;--j){
            mx = std::max(mx,a[j]);
            mn = std::min(mn,a[j]);
            f[i] = std::max(f[i],f[j - 1] + mx - mn);
        }
    }
    return f[n];
}
void update(long long &ans,int i,int x){
    if(i > 1 && i < n){
        if((diff[i - 1] < 0) != (diff[i] < 0)){
            ans += std::min(abs(diff[i - 1]),abs(diff[i]));
        }
    }
    if(i < n - 1){
        if((diff[i] < 0) != (diff[i + 1] < 0)){
            ans += std::min(abs(diff[i]),abs(diff[i + 1]));
        }
    }
    if(i < n && i > 0){
        ans -= abs(diff[i]);
    }
    diff[i] += x;
    if(i < n && i > 0){
        ans += abs(diff[i]);
    }
    if(i > 1 && i < n){
        if((diff[i - 1] < 0) != (diff[i] < 0)){
            ans -= std::min(abs(diff[i - 1]),abs(diff[i]));
        }
    }
    if(i < n - 1){
        if((diff[i] < 0) != (diff[i + 1] < 0)){
            ans -= std::min(abs(diff[i]),abs(diff[i + 1]));
        }
    }
}
void solve(){
//    long long ans = 0;
//    for(int i = 1;i < n;++i){
//        if(i < n - 1 && (diff[i] < 0) != (diff[i + 1] < 0)){
//            ans -= std::min(abs(diff[i]),abs(diff[i + 1]));
//        }
//        ans += abs(diff[i]);
//    }
//    std::cout << ans << newl;
    for(int i = 1;i <= q;++i){
        int l,r,x;
        std::cin >> l >> r >> x;
        for(int j = l;j <= r;++j){
            a[j] += x;
        }
        std::cout << calc() << newl;
    }
}
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);std::cout.tie(nullptr);
    readData();
    solve();
    return 0;
}

Compilation message

Main.cpp: In function 'long long int calc()':
Main.cpp:26:34: error: no matching function for call to 'max(int&, long long int&)'
   26 |             mx = std::max(mx,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
Main.cpp:26:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   26 |             mx = std::max(mx,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
Main.cpp:26:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   26 |             mx = std::max(mx,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
Main.cpp:26:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   26 |             mx = std::max(mx,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
Main.cpp:26:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   26 |             mx = std::max(mx,a[j]);
      |                                  ^
Main.cpp:27:34: error: no matching function for call to 'min(int&, long long int&)'
   27 |             mn = std::min(mn,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
Main.cpp:27:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   27 |             mn = std::min(mn,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
Main.cpp:27:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   27 |             mn = std::min(mn,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
Main.cpp:27:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   27 |             mn = std::min(mn,a[j]);
      |                                  ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
Main.cpp:27:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   27 |             mn = std::min(mn,a[j]);
      |                                  ^