Submission #137346

#TimeUsernameProblemLanguageResultExecution timeMemory
137346nvmdavaSalesman (IOI09_salesman)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; #define N 500005 #define pii pair<int, int> #define inf 2000000005 set<pii> in; int n, u, d, s, t, l, m; vector<pii> fair[N]; int dis(int f, int t){ return f <= t ? (t - f) * d : (f - t) * u; } int query(int loc){ int res1, res2; auto it = lower_bound(in.begin(), in.end(), {loc, -inf}); res1 = it == in.end() ? -inf : it -> ss - dis(it -> ff, loc); res2 = it == in.begin() ? -inf : (--it) -> ss - dis(it -> ff, loc); return max(res1, res2); } void update(int loc, int val){ if(query(loc) >= val) return; auto it = in.insert({loc, val}).ff; it++; while(it != in.end() && it -> ss <= val - dis(loc, it -> ff)) it = in.erase(it); it--; while(it != in.begin() && (--it) -> ss <= val - dis(loc, it -> ff)) it = in.erase(it); } vector<pii> tmp; int main(){ scanf("%d%d%d%d", &n, &u, &d, &s); for(int i = 1; i <= n; i++){ scanf("%d%d%d", &t, &l, &m); fair[t].push_back({l, m}); } update(s, 0); int sz; for(int i = 1; i < N; i++){ sz = fair[i].size(); if(sz == 0) continue; tmp.clear(); sort(fair[i].begin(), fair[i].end()); for(int j = 0; j < sz; j++){ int res = fair[i][j].ss + query(fair[i][j].ff); tmp.push_back({res, res}); } for(int j = 1; j < sz; j++) tmp[j].ff = max(tmp[j].ff, tmp[j - 1].ff - dis(fair[i][j - 1].ff, fair[i][j].ff) + fair[i][j].ss); for(int j = sz - 2; j >= 0; j--) tmp[j].ss = max(tmp[j].ss, tmp[j + 1].ss - dis(fair[i][j + 1].ff, fair[i][j].ff) + fair[i][j].ss); for(int j = 0; j < sz; j++) update(fair[i][j].ff, max(tmp[j].ff, tmp[j].ss)); } printf("%d", query(s)); }

Compilation message (stderr)

salesman.cpp: In function 'int query(int)':
salesman.cpp:19:57: error: no matching function for call to 'lower_bound(std::set<std::pair<int, int> >::iterator, std::set<std::pair<int, int> >::iterator, <brace-enclosed initializer list>)'
  auto it = lower_bound(in.begin(), in.end(), {loc, -inf});
                                                         ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from salesman.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:984:5: note: candidate: template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)
     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
     ^~~~~~~~~~~
/usr/include/c++/7/bits/stl_algobase.h:984:5: note:   template argument deduction/substitution failed:
salesman.cpp:19:57: note:   couldn't deduce template parameter '_Tp'
  auto it = lower_bound(in.begin(), in.end(), {loc, -inf});
                                                         ^
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 salesman.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:2023:5: note: candidate: template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)
     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
     ^~~~~~~~~~~
/usr/include/c++/7/bits/stl_algo.h:2023:5: note:   template argument deduction/substitution failed:
salesman.cpp:19:57: note:   candidate expects 4 arguments, 3 provided
  auto it = lower_bound(in.begin(), in.end(), {loc, -inf});
                                                         ^
salesman.cpp: In function 'int main()':
salesman.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &n, &u, &d, &s);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
salesman.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &t, &l, &m);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~