Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
//#define int long long
#define al(s) s.begin(),s.end()
#define INT_MAX 2147483647
typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef pair<int, ppi> pipp;
typedef pair<int, pi> pip;
typedef pair<long long, pi> llpi;

struct SegTree
{
	int N;
	vector<long long> Seg;
	void init(int n)
	{
		N = 1;
		while (N < n)N *= 2;
		for (int i = 0; i < N*2; i++)
		{
			Seg.push_back(INT_MAX);
		}
		
	}
	
	void update(int k, int a)
	{	
		k = k - 1 + N;
		Seg[k] = a;
		while (k > 0)
		{
			k = (k - 1) / 2;
			Seg[k] = min(Seg[2 * k + 1], Seg[2 * k + 2]);
		}
	}
	int find_min(int a, int b)
	{
		return query(a, b, 0, 0, N);
	}

	int query(int a, int b, int k, int l, int r)
	{
		if (r <= a || l >= b)return INT_MAX;
		if (l>=a&&r<=b)
		{
			return Seg[k];
		}
		else
		{
			return min(query(a, b, k * 2 + 1, l, (r + l) / 2),
					   query(a, b, k * 2 + 2, (r + l) / 2, r));
		}
	}
};

SegTree ss[4];//min,max

vector<llpi> a;
set<long long> s;
int main()
{
	long long ans = 0;
	long long n, d;
	cin >> n >> d;
	rei(4)ss[i].init(n);
	for (int i = 0; i < n; i++)
	{
		long long b;
		int x, y;
		cin >> x >> y >> b;
		a.push_back(llpi(b, pi(x, y)));
		s.insert(b);
	}
	for (int i = 0; i < n; i++)
	{
		int jj = 0;
		set<long long> ::iterator it = s.find(a[i].first);
		for (set<long long>::iterator l = s.begin(); l != it; l++)
		{
			jj++;
		}
		
		ss[0].update(jj, min(a[i].second.first, ss[0].Seg[jj + ss[0].N - 1]));
		ss[2].update(jj, min(a[i].second.first*(-1), ss[2].Seg[jj + ss[0].N - 1]));

		ss[1].update(jj, min(a[i].second.second, ss[1].Seg[jj + ss[0].N - 1]));
		ss[3].update(jj, min(a[i].second.second*(-1), ss[3].Seg[jj + ss[0].N - 1]));

	}
	bool end = false;
	for (int i = 0; i < s.size(); i++)
	{
		if(end)break;
		set<long long>::iterator it, ne;
		it = s.begin();
		for (int l = 0; l < i; l++)it++;
		ne = s.upper_bound(*it + d);
		if (ne == s.end())end = true;
		ne--;
		int coun = 0;
		for (; it != ne; it++)coun++;
		coun += i;
		coun++;
		ans = max( ans, ((-1) * ss[2].find_min(i, coun) - ss[0].find_min(i, coun)) * ((-1) * ss[3].find_min(i, coun) - ss[1].find_min(i, coun)) );
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:101:37: error: no matching function for call to 'min(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  101 |                 ss[0].update(jj, min(a[i].second.first, ss[0].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:101:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  101 |                 ss[0].update(jj, min(a[i].second.first, ss[0].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:11:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:101:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  101 |                 ss[0].update(jj, min(a[i].second.first, ss[0].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:102:37: error: no matching function for call to 'min(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  102 |                 ss[2].update(jj, min(a[i].second.first*(-1), ss[2].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:102:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  102 |                 ss[2].update(jj, min(a[i].second.first*(-1), ss[2].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:102:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  102 |                 ss[2].update(jj, min(a[i].second.first*(-1), ss[2].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:104:37: error: no matching function for call to 'min(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  104 |                 ss[1].update(jj, min(a[i].second.second, ss[1].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:104:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  104 |                 ss[1].update(jj, min(a[i].second.second, ss[1].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:104:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  104 |                 ss[1].update(jj, min(a[i].second.second, ss[1].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:105:37: error: no matching function for call to 'min(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
  105 |                 ss[3].update(jj, min(a[i].second.second*(-1), ss[3].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:105:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  105 |                 ss[3].update(jj, min(a[i].second.second*(-1), ss[3].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:105:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  105 |                 ss[3].update(jj, min(a[i].second.second*(-1), ss[3].Seg[jj + ss[0].N - 1]));
      |                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:122:26: error: no matching function for call to 'max(long long int&, int)'
  122 |                 ans = max( ans, ((-1) * ss[2].find_min(i, coun) - ss[0].find_min(i, coun)) * ((-1) * ss[3].find_min(i, coun) - ss[1].find_min(i, coun)) );
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argumen