Pagini recente » Cod sursa (job #2980492) | Cod sursa (job #368998) | Cod sursa (job #3273639) | Cod sursa (job #2980488) | Cod sursa (job #3273812)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("cutii.in");
ofstream out("cutii.out");
const int NMAX = 3500;
struct ura{
int x, y, z;
}v[NMAX + 2];
int aib[NMAX + 2][NMAX + 2], n;
bool cmp(ura a, ura b){
if(a.x == b.x){
if(a.y == b.y){
return a.z < b.z;
}
return a.y < b.y;
}
return a.x < b.x;
}
void update(int lin, int col, int val){
for(int i = lin;i<=n;i+= i & -i){
for(int j = col;j<=n;j+= j & -j){
aib[i][j] = max(aib[i][j], val);
}
}
}
void clear(int lin, int col){
for(int i = lin;i<=n;i+= i & -i){
for(int j = col;j<=n;j+= j & -j){
aib[i][j] = 0;
}
}
}
int query(int lin, int col){
int rez = 0;
for(int i = lin;i;i -= i & -i){
for(int j = col;j;j -= j & -j){
rez = max(rez, aib[i][j]);
}
}
return rez;
}
int main(){
int t;
in>>n>>t;
while(t--){
for(int i = 1;i<=n;i++){
in>>v[i].x>>v[i].y>>v[i].z;
}
int maxi = 0;
sort(v + 1, v + n + 1, cmp);
for(int i = 1;i<=n;i++){
int current = query(v[i].y - 1, v[i].z - 1);
maxi = max(maxi, current + 1);
update(v[i].y, v[i].z, current + 1);
}
out<<maxi<<"\n";
for(int i = 1;i<=n;i++){
clear(v[i].y, v[i].z);
}
}
return 0;
}