Pagini recente » Cod sursa (job #1015414) | Cod sursa (job #1348832) | Cod sursa (job #2010348) | Cod sursa (job #3193090) | Cod sursa (job #2910030)
#include <fstream>
#include <algorithm>
#include <string.h>
using namespace std;
const int MAX_N = 3500;
pair<short int, short int> aib[MAX_N + 1][MAX_N + 1];
struct cutie {
int x;
int y;
int z;
};
cutie a[MAX_N + 1];
int n, t;
void update(int x, int y, short int val, int test) {
for (int i = x; i <= n; i += i & -i) {
for (int j = y; j <= n; j += j & -j) {
// aib[i][j] = max(aib[i][j], val);
if (aib[i][j].second == test) {
aib[i][j].first = max(aib[i][j].first, val);
} else {
aib[i][j] = {val, test};
}
}
}
}
int query(int x, int y, int test) {
short int answer = 0;
for (int i = x; i >= 1; i -= i & -i) {
for (int j = y; j >= 1; j -= j & -j) {
if (aib[i][j].second == test) {
answer = max(answer, aib[i][j].first);
}
}
}
return answer;
}
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
int main() {
InParser fin("cutii.in");
ofstream fout("cutii.out");
fin >> n >> t;
for (int test = 1; test <= t; test++) {
for (int i = 1; i <= n; i++) {
int x;
fin >> x;
fin >> a[x].y >> a[x].z;
}
// memset(aib, 0, sizeof(aib));
int answer = 0;
for (int i = 1; i <= n; i++) {
int tmp = query(a[i].y, a[i].z, test) + 1;
answer = max(answer, tmp);
update(a[i].y, a[i].z, tmp, test);
}
fout << answer << "\n";
}
return 0;
}