Pagini recente » Cod sursa (job #1726332) | Cod sursa (job #405403) | Cod sursa (job #1798515) | Cod sursa (job #2260313) | Cod sursa (job #2349259)
#include <bits/stdc++.h>
using namespace std;
ifstream f("cutii.in");
ofstream g("cutii.out");
int T,N;
class Fenwick_2D{
private:
int N;
int **A;
void asc(int &x){
x+=(x&(-x));
}
void desc(int &x){
x-=(x&(-x));
}
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(int x,int y,int val){
for(int i=x;i<=N;asc(i))
for(int j=y;j<=N;asc(j))
A[i][j]+=val;
}
int query(int x, int y){
int sum=0;
for(int i=x;i>0;desc(i))
for(int j=y;j>0;desc(j))
sum+=A[i][j];
return sum;
}
};
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 main(){
ios_base::sync_with_stdio(false);
f>>N>>T;
vector <box> v(N);
while(T--){
Fenwick_2D BIT(N);
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);
}
g<<ans-1<<'\n';
}
return 0;
}