Pagini recente » Cod sursa (job #1520680) | Cod sursa (job #1686941) | Cod sursa (job #790046) | Cod sursa (job #2322244) | Cod sursa (job #2644271)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
const short NMAX = 3501;
short aib[NMAX][NMAX],n;
struct cutie{short x, y, z;};
bool cmp(cutie a, cutie b){
return a.x<b.x || (a.x==b.x && (a.y<b.y || (a.y==b.y && a.z<b.z)));
}
short lastBit(short num){
return num&-num;
}
void insert2(short pos1, short pos2, short val, short aib[][NMAX]){
while(pos2<NMAX){
aib[pos1][pos2]=max(aib[pos1][pos2],val);
pos2+=lastBit(pos2);
}
}
void insert(short pos1,short pos2, short val, short aib[][NMAX]){
while(pos1<NMAX){
insert2(pos1,pos2,val,aib);
pos1+=lastBit(pos1);
}
}
short getmax2(short pos1,short pos2, short aib[][NMAX]){
short Max=0;
while(pos2){
Max=max(Max,aib[pos1][pos2]);
pos2-=lastBit(pos2);
}
return Max;
}
short getmax(short pos1,short pos2, short aib[][NMAX]){
short Max=0;
while(pos1){
Max=max(Max,getmax2(pos1,pos2,aib));
pos1-=lastBit(pos1);
}
return Max;
}
void tc(){
short dp[NMAX]{},ans=0;
cutie v[NMAX];
short aib[NMAX][NMAX]{};
for(short i=0;i<n;i++){
fin>>v[i].x>>v[i].y>>v[i].z;
}
sort(v,v+n,cmp);
for(short i=0;i<n;i++){
dp[i]=getmax(v[i].y-1,v[i].z-1, aib)+1;
insert(v[i].y,v[i].z,dp[i], aib);
ans=max(ans,dp[i]);
}
fout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false); fin.tie(0); fout.tie(0);
short k; fin>>n>>k; while(k--)
tc();
return 0;
}