제출 #375040

#제출 시각아이디문제언어결과실행 시간메모리
375040ijxjdjdSalesman (IOI09_salesman)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define FR(i, N) for (int i = 0; i < int(N); i++) #define all(x) begin(x), end(x) using namespace std; using ll = long long; const int MAXN = (int)(5e5) + 5; const int INF = (int)(1.5e9); vector<pair<int, int>> byTime[MAXN]; int N, U, D, S; int segDirect[2][4*MAXN]; int segBack[2][4*MAXN]; void pull(int n) { for (int j = 0; j < 2; j++) { segDirect[j][n] = max(segDirect[j][2*n], segDirect[j][2*n+1]); segBack[j][n] = max(segBack[j][2*n], segBack[j][2*n+1]); } } pair<ll, ll> query(int l, int r, bool right, int n = 1, int tl = 0, int tr = MAXN-1) { if (l > tr || r < tl) { return {-INF, -INF}; } else if (l <= tl && tr <= r) { return {segDirect[right][n], segBack[right][n]}; } else { int tm = (tl + tr)/2; auto p1 = query(l, r, right, 2*n, tl, tm); auto p2 = query(l, r, right, 2*n+1, tm+1, tr); return {max(p1.first, p2.first), max(p1.second, p2.second)}; } } void upd(int i, int val, int n = 1, int tl = 0, int tr = MAXN-1) { if (tl == tr) { segBack[1][n] = val-U*i; segDirect[1][n] = val-U*i+i*(U+D); segBack[0][n] = val+D*i; segDirect[0][n] = val+D*i-i*(D+U); } else { int tm = (tl + tr)/2; if (i <= tm) { upd(i, val, 2*n, tl, tm); } else { upd(i, val, 2*n+1, tm+1, tr); } pull(n); } } int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> N >> U >> D >> S; for (int i = 0; i < N; i++) { int T, L, K; cin >> T >> L >> K; byTime[T].push_back({L, K}); } for (int i = 0; i < 4*MAXN; i++) { segBack[0][i] = -INF; segBack[1][i] = -INF; segDirect[0][i] = -INF; segDirect[1][i] = -INF; } int ans = -INF; upd(S, 0); for (auto& t : byTime) { sort(all(t)); vector<int> res(t.size(), -INF); ll curDirect = -INF; ll curBack = -INF; ll backKeep = -INF; ll lst = MAXN; for (int i = int(t.size())-1; i>=0; i--) { auto qs = query(t[i].first, lst-1, false); curDirect = max(curDirect, qs.first) + t[i].second; curBack = max(curBack, backKeep + qs.second); res[i] = max(res[i], curDirect+U*t[i].first); res[i] = max(res[i], curBack+U*t[i].first+t[i].second); backKeep = max(backKeep, -t[i].first*(D+U)); backKeep += t[i].second; curBack += t[i].second; lst = t[i].first; } curDirect = -INF; curBack = -INF; backKeep = -INF; lst = -1; for (int i = 0; i < t.size(); i++) { auto qs = query(lst+1, t[i].first, true); curDirect = max(curDirect, qs.first) + t[i].second; curBack = max(curBack, backKeep + qs.second); res[i] = max(res[i], curDirect - D*t[i].first); res[i] = max(res[i], curBack - D*t[i].first + t[i].second); backKeep = max(backKeep, t[i].first*(D+U)); backKeep += t[i].second; curBack += t[i].second; lst = t[i].first; } for (int i = 0; i < t.size(); i++) { if (t[i].first < S) { ans = max(ans, res[i] - (S-t[i].first)*D); } else { ans = max(ans, res[i] - (t[i].first-S)*U); } upd(t[i].first, res[i]); } } cout << ans << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

salesman.cpp: In function 'int main()':
salesman.cpp:84:56: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, ll)'
   84 |             res[i] = max(res[i], curDirect+U*t[i].first);
      |                                                        ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
salesman.cpp:84:56: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   84 |             res[i] = max(res[i], curDirect+U*t[i].first);
      |                                                        ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
salesman.cpp:84:56: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   84 |             res[i] = max(res[i], curDirect+U*t[i].first);
      |                                                        ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
salesman.cpp:84:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   84 |             res[i] = max(res[i], curDirect+U*t[i].first);
      |                                                        ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
salesman.cpp:84:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   84 |             res[i] = max(res[i], curDirect+U*t[i].first);
      |                                                        ^
salesman.cpp:85:66: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, ll)'
   85 |             res[i] = max(res[i], curBack+U*t[i].first+t[i].second);
      |                                                                  ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
salesman.cpp:85:66: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   85 |             res[i] = max(res[i], curBack+U*t[i].first+t[i].second);
      |                                                                  ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
salesman.cpp:85:66: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   85 |             res[i] = max(res[i], curBack+U*t[i].first+t[i].second);
      |                                                                  ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
salesman.cpp:85:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   85 |             res[i] = max(res[i], curBack+U*t[i].first+t[i].second);
      |                                                                  ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
salesman.cpp:85:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   85 |             res[i] = max(res[i], curBack+U*t[i].first+t[i].second);
      |                                                                  ^
salesman.cpp:87:55: error: no matching function for call to 'max(ll&, int)'
   87 |             backKeep = max(backKeep, -t[i].first*(D+U));
      |                                                       ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
salesman.cpp:87:55: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   87 |             backKeep = max(backKeep, -t[i].first*(D+U));
      |                                                       ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
salesman.cpp:87:55: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   87 |             backKeep = max(backKeep, -t[i].first*(D+U));
      |                                                       ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
salesman.cpp:87:55: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   87 |             backKeep = max(backKeep, -t[i].first*(D+U));
      |                                                       ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
salesman.cpp:87:55: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   87 |             backKeep = max(backKeep, -t[i].first*(D+U));
      |                                                       ^
salesman.cpp:98:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for (int i = 0; i < t.size(); i++) {
      |                         ~~^~~~~~~~~~
salesman.cpp:104:58: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, ll)'
  104 |             res[i] = max(res[i], curDirect - D*t[i].first);
      |                                                          ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
salesman.cpp:104:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  104 |             res[i] = max(res[i], curDirect - D*t[i].first);
      |                                                          ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
salesman.cpp:104:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  104 |             res[i] = max(res[i], curDirect - D*t[i].first);
      |                                                          ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
salesman.cpp:104:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  104 |             res[i] = max(res[i], curDirect - D*t[i].first);
      |                                                          ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
salesman.cpp:104:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  104 |             res[i] = max(res[i], curDirect - D*t[i].first);
      |                                                          ^
salesman.cpp:105:70: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, ll)'
  105 |             res[i] = max(res[i], curBack - D*t[i].first + t[i].second);
      |                                                                      ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
salesman.cpp:105:70: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  105 |             res[i] = max(res[i], curBack - D*t[i].first + t[i].second);
      |                                                                      ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
salesman.cpp:105:70: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
  105 |             res[i] = max(res[i], curBack - D*t[i].first + t[i].second);
      |                                                                      ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
salesman.cpp:105:70: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  105 |             res[i] = max(res[i], curBack - D*t[i].first + t[i].second);
      |                                                                      ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from salesman.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note