Pagini recente » Cod sursa (job #2429934) | Cod sursa (job #1909882) | Cod sursa (job #2415118) | Cod sursa (job #287074) | Cod sursa (job #2633798)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in ("cutii.in");
ofstream out("cutii.out");
int n, t, x, y, z;
vector < pair <int, int> > boxes;
vector < vector <int> > dp;
inline int look(int x, int y)
{
int maxi=0;
while(x>0&&y>0)
{
maxi=max(maxi, dp[x][y]);
x-=x&(-x);
y-=y&(-y);
}
return maxi;
}
inline void update(int x, int y, int val)
{
while(x<=n)
{
int yp=y;
while(yp<=n)
{
dp[x][yp]=max(dp[x][yp], val);
yp+=yp&(-yp);
}
x+=x&(-x);
}
}
int main()
{
in>>n>>t;
boxes.resize(n+1);
dp.resize(n+1, vector <int> (n+1, 0));
while(t--)
{
int maxx=0;
for(int i=1; i<=n; i++)
in>>x>>y>>z, boxes[x]={y, z};
for(int i=1; i<=n; i++)
{
int val=look(boxes[i].first-1, boxes[i].second-1);
update(boxes[i].first, boxes[i].second, val+1);
maxx=max(maxx, val+1);
}
for(int i=1; i<=n; i++)
dp[boxes[i].first][boxes[i].second]=0;
out<<maxx<<"\n";
}
return 0;
}