Pagini recente » Cod sursa (job #2810498) | Cod sursa (job #2887422) | Cod sursa (job #1012555) | Cod sursa (job #2512091) | Cod sursa (job #2349281)
#include <bits/stdc++.h>
using namespace std;
ifstream f("cutii.in");
ofstream g("cutii.out");
struct box{
int x,y,z;
bool operator < (const box &other) const{
if(x==other.x){
if(y==other.y)
return z<other.z;
return y<other.y;
}
return x<other.x;
}
};
int T,N;
vector <box> v;
class Fenwick_2D{
private:
int N;
int **A;
void asc(int &x){
x+=(x&(-x));
}
void desc(int &x){
x-=(x&(-x));
}
void __clear__(const int &x, const int &y){
for(int i=x;i<=N;asc(i))
for(int j=y;j<=N;asc(j))
A[i][j]=0;
}
public:
Fenwick_2D(const int &n){
N=n;
A=new int*[n+5]();
for(int i=0;i<n+5;i++)
A[i]=new int[n+5]();
}
void update(const int &x, const int &y, const int &val){
for(int i=x;i<=N;asc(i))
for(int j=y;j<=N;asc(j))
A[i][j]=max(A[i][j],val);
}
int query(const int &x, const int &y){
int maxx=0;
for(int i=x;i>0;desc(i))
for(int j=y;j>0;desc(j))
maxx=max(A[i][j],maxx);
return maxx;
}
void _clear(){
for(int i=0;i<N;i++)
__clear__(v[i].y,v[i].z);
}
};
int main(){
ios_base::sync_with_stdio(false);
f>>N>>T;
v.resize(N);
Fenwick_2D BIT(N);
while(T--){
for(int i=0;i<N;i++)
f>>v[i].x>>v[i].y>>v[i].z;
sort(v.begin(),v.end());
int ans=0;
for(int i=0;i<N;i++){
int val=BIT.query(v[i].y,v[i].z);
BIT.update(v[i].y,v[i].z,val+1);
ans=max(ans,val+1);
}
BIT._clear();
g<<ans<<'\n';
}
return 0;
}