Pagini recente » Cod sursa (job #2975007) | Cod sursa (job #3188107) | Cod sursa (job #1391461) | Cod sursa (job #1368322) | Cod sursa (job #212290)
Cod sursa(job #212290)
#include <fstream>
#include <algorithm>
using namespace std;
typedef struct cutie{
int x,y,z;
};
const int NMAX=3501;
int N,T,s[NMAX][NMAX];
cutie a[NMAX];
ifstream f("cutii.in");
ofstream g("cutii.out");
int cmp(cutie A,cutie B){
return A.z<B.z;
}
void update(int x,int y,int val){
int j;
while (x<=N){
j=y;
while (j<=N){
s[x][j]=max(s[x][j],val);
j=(j|(j-1))+1;}
x=(x|(x-1))+1;
}
}
void curata(int x,int y){
int j;
while (x<=N){
j=y;
while (j<=N){
s[x][j]=0;
j=(j|(j-1))+1;}
x=(x|(x-1))+1;
}
}
int query(int x,int y){
int j,w=0;
while (x>0){
j=y;
while (j>0){
w=max(w,s[x][j]);
j&=(j-1);}
x&=(x-1);
}
return w;
}
int solve(){
int i,sol=0,w;
sort(a,a+N+1,cmp);
for (i=1;i<=N;++i)
curata(a[i].x,a[i].y);
for (i=1;i<=N;++i){
w=query(a[i].x,a[i].y);
update(a[i].x,a[i].y,w+1);
sol=max(sol,w+1);
}
return sol;
}
int main(){
f>>N>>T;
while (T--){
for (int i=1;i<=N;++i)
f>>a[i].x>>a[i].y>>a[i].z;
g<<solve()<<'\n';
}
return 0;
}