Cod sursa(job #2644292)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 24 august 2020 10:45:23
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda prbd2 Marime 2.2 kb
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000003
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define NMAX 3505

int aib2d[NMAX][NMAX], n, t;

struct chestie{
	int x, y, z;
}v[NMAX];

inline bool cmp(chestie a, chestie b){
	return a.x < b.x;
}

void getUpd(int pz1, int pz2, int val){
	for(int poz1 = pz2; poz1 <= n; poz1 += zeros(poz1))
		for(int poz2 = pz2; poz2 <= n; poz2 += zeros(poz2))
			if(val == -1)
				aib2d[poz1][poz2] = 0;
			else aib2d[poz1][poz2] = max(aib2d[poz1][poz2], val);
}

int getRez(int pz1, int pz2){
	int maxx = 0;
	for(int poz1 = pz1; poz1 >= 1; poz1 -= zeros(poz1))
		for(int poz2 = pz2; poz2 >= 1; poz2 -= zeros(poz2))
			maxx = max(maxx, aib2d[poz1][poz2]);
	return maxx;
}

int main(){
	freopen("cutii.in", "r", stdin);
	freopen("cutii.out", "w", stdout);

	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> n >> t;
	while(t--){
		for(int i = 1; i <= n; ++i)
			cin >> v[i].x >> v[i].y >> v[i].z;

		sort(v + 1, v + n + 1, cmp);

		int rez = 0;
		for(int i = 1; i <= n; ++i){
			int cnt = getRez(v[i].y, v[i].z) + 1;
			getUpd(v[i].y, v[i].z, cnt);
			rez = max(rez, cnt);
		}

		cout << rez << '\n';
		for(int i = 1; i <= n; ++i)
			getUpd(v[i].y, v[i].z, -1);
	}
	return 0;
}