Pagini recente » Cod sursa (job #766446) | Cod sursa (job #1352736) | Cod sursa (job #2863136) | Cod sursa (job #1127618) | Cod sursa (job #3196501)
#include <bits/stdc++.h>
using namespace std;
#define INFILE "cutii.in"
#define OUTFILE "cutii.out"
const int N_MAX = 3505;
const int MINIM = -1;
struct Box {
int x;
int y;
int z;
Box() : x(0), y(0), z(0) {}
Box(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
bool operator<(const Box &other) const {
return (this -> x < other.x);
}
};
struct Fenwick {
int n;
vector<vector<int> > aib;
Fenwick() : n(0){}
Fenwick(int _n) : n(_n) {
aib.resize(n + 1, vector<int>(n + 1));
}
int query(int x, int y){
int maxim = MINIM;
for(int i = x; i > 0; i -= (i & -i)){
for(int j = y; j > 0; j -= (j & -j)){
maxim = max(maxim, aib[i][j]);
}
}
return maxim;
}
void update(int x, int y, int value){
for(int i = x; i <= n; i += (i & -i)){
for(int j = y; j <= n; j += (j & -j)){
aib[i][j] = max(aib[i][j], value);
}
}
}
};
int n;
void solve(){
int ans = 0;
vector<Box> v(n);
Fenwick aib(n);
for(int i = 0; i < n; ++i){
int x, y, z; cin >> x >> y >> z; v[i] = Box(x, y, z);
}
sort(v.begin(), v.end());
for(int i = 0; i < n; ++i){
auto aux = aib.query(v[i].y, v[i].z) + 1;
aib.update(v[i].y, v[i].z, aux);
ans = max(ans, aux);
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
freopen(INFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
cin.tie(0), cout.tie(0);
int tests; cin >> n >> tests;
for(int i = 0; i < tests; ++i) solve();
return 0;
}