Language: C++

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cstdio>
using namespace std;
#define MAX_N 200000
#define F first
#define Se second
#define MP(i, j) make_pair((i), (j))
#define int long long
struct S{
	int sx, lx, sy, ly;
	S(int isx, int ilx, int isy, int ily): sx(isx), lx(ilx), sy(isy), ly(ily){}
	bool operator<(const S &s) const { 
		return 1;
	}
};
int cnt;
void init(int n_, int *dat){
	cnt = 1;
	while(cnt < n_) cnt *= 2;
	for(int i = 0; i < 2 * cnt - 1; i++) dat[i] = INT_MAX;
}
void update(int k, int a, int *dat){
	k += cnt - 1;
	dat[k] = a;
	while(k > 0){
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}
int query(int a, int b, int k, int l, int r, int *dat){
	if(r <= a || b <= l) return INT_MAX;
	if(a <= l && r <= b) return dat[k];
	else{
		int v1 = query(a, b, k * 2 + 1, l, (l + r) / 2, dat);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r, dat);
		return min(v1, vr);
	}
}
typedef pair<int, S> PS;
typedef vector<PS>::iterator it;

int i, j, n, d, stars[MAX_N][3], ax[2 * N], bx[2 * N], ay[2 * N], by[2 * N];
int ans = 0;
vector<PS> vec;

void vdc(vector<PS> &vf, S s, int now){
	if(vf[now].Se.sx > s.sx)
		vf[now].Se.sx = s.sx;
	if(vf[now].Se.lx < s.lx)
		vf[now].Se.lx = s.lx;
	if(vf[now].Se.sy > s.sy)
		vf[now].Se.sy = s.sy;
	if(vf[now].Se.ly < s.ly)
		vf[now].Se.ly = s.ly;
}

signed main(){
	cin >> n >> d;
	vec.push_back(MP(-1, S(0, 0, 0, 0)));
	for(i = 0; i < n; i++){
		int a, b, c;
		cin >> a >> b >> c;
		S s = S(a, a, b, b);
		it ite = lower_bound(vec.begin(), vec.end(), MP(c, s));
		if(vec[ite - vec.begin() - 1].F != c){
			vec.insert(ite, MP(c, s));
		}
		else{
			vdc(vec, s, ite - vec.begin() - 1);
		}
	}
	init(vec.size(), ax);
	init(vec.size(), bx);
	init(vec.size(), ay);
	init(vec.size(), by);
	S s = S(INT_MAX, 0, INT_MAX, 0);
	vec.erase(vec.begin());
	for(i = 0; i < vec.size(); i++){
		update(i, vec[i].Se.sx, ax);
		update(i, -vec[i].Se.lx, bx);
		update(i, vec[i].Se.sy, ay);
		update(i, -vec[i].Se.ly, by);
	}
	i = 0; j = 0;
	for(;;){
		while(j < vec.size()){
			if(vec[j].F - vec[i].F <= d)
				j++;
			else
				break;
		}
		ans = max(ans, (-query(i, j, 0, 0, cnt, bx) - query(i, j, 0, 0, cnt, ax)) * (-query(i, j, 0, 0, cnt, by) - query(i, j, 0, 0, cnt, ay)));
		if(j == vec.size())
			break;
		i++;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:47:41: error: 'N' was not declared in this scope
   47 | int i, j, n, d, stars[MAX_N][3], ax[2 * N], bx[2 * N], ay[2 * N], by[2 * N];
      |                                         ^
a.cc:47:52: error: 'N' was not declared in this scope
   47 | int i, j, n, d, stars[MAX_N][3], ax[2 * N], bx[2 * N], ay[2 * N], by[2 * N];
      |                                                    ^
a.cc:47:63: error: 'N' was not declared in this scope
   47 | int i, j, n, d, stars[MAX_N][3], ax[2 * N], bx[2 * N], ay[2 * N], by[2 * N];
      |                                                               ^
a.cc:47:74: error: 'N' was not declared in this scope
   47 | int i, j, n, d, stars[MAX_N][3], ax[2 * N], bx[2 * N], ay[2 * N], by[2 * N];
      |                                                                          ^
a.cc: In function 'int main()':
a.cc:77:26: error: 'ax' was not declared in this scope
   77 |         init(vec.size(), ax);
      |                          ^~
a.cc:78:26: error: 'bx' was not declared in this scope
   78 |         init(vec.size(), bx);
      |                          ^~
a.cc:79:26: error: 'ay' was not declared in this scope
   79 |         init(vec.size(), ay);
      |                          ^~
a.cc:80:26: error: 'by' was not declared in this scope
   80 |         init(vec.size(), by);
      |                          ^~