Submission #671425

# Submission time Handle Problem Language Result Execution time Memory
671425 2022-12-13T04:49:28 Z viwlesxq Divide and conquer (IZhO14_divide) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

typedef int64_t ll;
typedef string str;

#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freo("divide");
	int n;
	cin >> n;
	ll x[n], g[n], d[n];
	for (int i = 0; i < n; i++) cin >> x[i] >> g[i] >> d[i];
	ll ans = *max_element(g, g + n);
	vector <ll> pref_d(n), pref_g(n), pref_need(n);
	pref_d[0] = d[0];
	pref_g[0] = g[0];
	ll need = 0;
	for (int i = 1; i < n; i++) {
		pref_d[i] = pref_d[i - 1] + d[i];
		pref_g[i] = pref_g[i - 1] + g[i];
		need = max(x[i] - x[0] - pref_d[i], 0ll);
		if (!need) ans = max(ans, pref_g[i]);
		else {
			int l = 0, r = i;
			while (l + 1 < r) {
				int mid = (l + r) / 2;
				if (pref_d[i] - pref_d[mid - 1] >= x[i] - x[mid]) r = mid;
				else l = mid;
			}
			ans = max(ans, pref_g[i] - pref_g[r - 1]);
		}
	}
	cout << ans;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:40:42: error: no matching function for call to 'max(ll, long long int)'
   40 |   need = max(x[i] - x[0] - pref_d[i], 0ll);
      |                                          ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from divide.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:
divide.cpp:40:42: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   40 |   need = max(x[i] - x[0] - pref_d[i], 0ll);
      |                                          ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from divide.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:
divide.cpp:40:42: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   40 |   need = max(x[i] - x[0] - pref_d[i], 0ll);
      |                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from divide.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:
divide.cpp:40:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   40 |   need = max(x[i] - x[0] - pref_d[i], 0ll);
      |                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from divide.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:
divide.cpp:40:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   40 |   need = max(x[i] - x[0] - pref_d[i], 0ll);
      |                                          ^
divide.cpp: In function 'void freo(str)':
divide.cpp:21:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:21:67: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
      |                                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~