Cod sursa(job #3152815)

Utilizator IanisBelu Ianis Ianis Data 26 septembrie 2023 20:52:59
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>

#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()

#define fi first
#define se second

#define lsb(x) (x & (-x))

using namespace std;

#ifdef LOCAL
ifstream fin("input.txt");
#define fout cout
#else
#define FILE_NAME "cutii"
ifstream fin(FILE_NAME ".in");
ofstream fout(FILE_NAME ".out");
#define endl '\n'
#endif

const int NMAX = 3505;
const int INF = 1e9+5;

struct Box {
	int x, y, z;
};

int n;
Box a[NMAX];
int aib[NMAX][NMAX];

void aib_update(int x, int y, int val) {
	for (int i = x; i <= n; i += lsb(i))
		for (int j = y; j <= n; j += lsb(j))
			aib[i][j] += val;
}

int aib_query(int x, int y) {
	x = n - x + 1;
	y = n - y + 1;
	int ret = 0;
	for (int i = x; i >= 1; i -= lsb(i))
		for (int j = y; j >= 1; j -= lsb(j))
			ret += aib[i][j];
	return ret;
}

void read() {
	for (int i = 1; i <= n; i++)
		fin >> a[i].x >> a[i].y >> a[i].z;
}

int solve() {
	sort(a + 1, a + n + 1, [](const Box &a, const Box &b) {
		return a.z > b.z;
	});

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		aib_update(a[i].x, a[i].y, 1);
		ans = max(ans, aib_query(a[i].x, a[i].y));
	}

	for (int i = 1; i <= n; i++)
		aib_update(a[i].x, a[i].y, -1);
	return ans;
}

int main() {
	int t = 1;
	fin >> n >> t;

	while (t--) {
		read();
		fout << solve() << endl;
	}

	return 0;
}