Cod sursa(job #1467993)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 5 august 2015 03:35:36
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
 
class max_aib_2d{
	int buf[3501][3501];
	const int sz;
public:
	max_aib_2d(const int n):
		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; }
	void reset(const int x, const int y){
		for(int xx = x; xx <= sz; xx += xx&-xx){
			for(int yy = y; yy <= sz; yy += yy&-yy){
				buf[xx][yy] = 0; } } } };
 
int fa_test(ifstream& f, const int n){
	static max_aib_2d lung_max(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; }
	for(const auto c : cutii){
		lung_max.set(c.first, c.second, lung_max.get(c.first-1, c.second-1)+1); }
	const int rez = lung_max.get(n, n);
	for(const auto c : cutii){
		lung_max.reset(c.first, c.second); }
	return rez; }
 
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; }