Pagini recente » Cod sursa (job #2435266) | Cod sursa (job #914947) | Cod sursa (job #3201151) | Cod sursa (job #2416524) | Cod sursa (job #3186772)
#include <fstream>
// #include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
template<const int& func(const int&, const int&)>
class Fenwick2D {
public:
Fenwick2D(int n) : ys(n + 1) {}
void fakeUpdate(int x, int y) {
for (x++; x < ys.size(); x += dx(x)) {
ys[x].push_back(y);
}
}
void build() {
for (auto& y : ys) {
sort(y.begin(), y.end());
y.erase(unique(y.begin(), y.end()), y.end());
t.emplace_back(y.size() + 1);
}
}
void update(int x, int y, int val) {
for (x++; x < ys.size(); x += dx(x)) {
for (int i = ind(x, y); i < t[x].size(); i += dx(i)) {
t[x][i] = func(t[x][i], val);
}
}
}
int query(int x, int y) {
int result = 0;
for (; x > 0; x -= dx(x)) {
for (int i = ind(x, y); i > 0; i -= dx(i)) {
result = func(result, t[x][i]);
}
}
return result;
}
private:
vector<vector<int>> ys;
vector<vector<int>> t;
inline int dx(int x) { return (x & (-x)); }
int ind(int x, int y) {
return (upper_bound(ys[x].begin(), ys[x].end(), y) - ys[x].begin());
}
};
void Solve(int n) {
Fenwick2D<std::max> aib(n);
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) {
int a, b, c; cin >> a >> b >> c;
v[a - 1] = {b, c};
aib.fakeUpdate(b, c);
}
aib.fakeUpdate(0, 0);
aib.build();
aib.update(0, 0, 0);
int ans = 0;
for (auto [x, y] : v) {
int len = aib.query(x, y) + 1;
ans = max(ans, len);
aib.update(x, y, len);
}
cout << ans << "\n";
}
int main() {
int n, t; cin >> n >> t;
for (int i = 0; i < t; i++) {
Solve(n);
}
return 0;
}