Pagini recente » Cod sursa (job #309565) | Cod sursa (job #700161) | Cod sursa (job #2370216) | Cod sursa (job #2759228) | Cod sursa (job #2323434)
#include <fstream>
#include <cstring>
#include <algorithm>
#define DIM 3505
#define x first
#define y second.first
#define z second.second
#define lsb(a) ((a)^((a)-1))&(a)
using namespace std;
#include <stdio.h>
#include <ctype.h>
FILE *_fin;
int _in_loc; char _in_buff[4096];
void read_init(const char* nume)
{
_fin = fopen(nume, "r");
_in_loc = 4095;
}
char read_ch()
{
++_in_loc;
if (_in_loc == 4096) {
_in_loc = 0;
fread(_in_buff, 1, 4096, _fin);
}
return _in_buff[_in_loc];
}
int read_u32()
{
int u32 = 0; char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
sgn = -1;
} else {
u32 = c - '0';
}
while (isdigit(c = read_ch())) {
u32 = u32 * 10 + c - '0';
}
return u32 * sgn;
}
ofstream fo("cutii.out");
int T;
int n;
pair<int,pair<int,int> > p[DIM];
short int AIB[DIM][DIM];
char last[DIM][DIM];
void update(int a,int b,short int val,char test)
{
for(int i=a;i<=n;i+=lsb(i))
for(int j=b;j<=n;j+=lsb(j))
if(last[i][j]==test)
AIB[i][j]=max(AIB[i][j],val);
else
AIB[i][j]=val,last[i][j]=test;
}
short int query(int a,int b,char test)
{
short int rez=0;
for(int i=a;i>0;i-=lsb(i))
for(int j=b;j>0;j-=lsb(j))
if(last[i][j]==test)
rez=max(rez,AIB[i][j]);
return rez;
}
int main()
{
read_init("cutii.in");
n=read_u32(),T=read_u32();
for(int t=0;t<T;t++)
{
for(int i=1;i<=n;i++)
p[i].x=read_u32(),p[i].y=read_u32(),p[i].z=read_u32();
sort(p+1,p+n+1);
for(int i=1;i<=n;i++)
update(p[i].y,p[i].z,query(p[i].y-1,p[i].z-1,t)+1,t);
fo<<query(n,n,t)<<"\n";
}
fo.close();
return 0;
}