Cod sursa(job #1465118)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 26 iulie 2015 15:31:15
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <vector>
#include <utility>
using namespace std;

class max_aib_2d{
	vector<vector<int> > buf;
	const int sz;
public:
	max_aib_2d(const int n):
		buf(n+1, vector<int>(n+1, 0)),
		sz(n){}
	void set(const int x, const int y, const int val){
		for(int xx = x; xx <= sz; xx += xx&-xx){
			for(int yy = y; yy <= sz; yy += yy&-yy){
				buf[xx][yy] = max(buf[xx][yy], val); } } }
	int get(const int x, const int y){
		int rez = 0;
		for(int xx = x; xx > 0; xx -= xx&-xx){
			for(int yy = y; yy > 0; yy -= yy&-yy){
				rez = max(rez, buf[xx][yy]); } }
		return rez; } };

int fa_test(ifstream& f, const int n){
	vector<pair<int, int> > cutii(n);
	for(int i = 0, x; i < n; ++i){
		f >> x;
		f >> cutii[x-1].first >> cutii[x-1].second; }
	max_aib_2d lung_max(n);
	for(const auto c : cutii){
		lung_max.set(c.first, c.second, lung_max.get(c.first-1, c.second-1)+1); }
	return lung_max.get(n, n); }

int main(){
	ifstream f("cutii.in");
	ofstream g("cutii.out");
	int n, t;
	f >> n >> t;
	for(int i = 0; i < t; ++i){
		g << fa_test(f, n) << '\n'; }
	return 0; }