Pagini recente » Cod sursa (job #966404) | Cod sursa (job #2515148) | Cod sursa (job #2360780) | Cod sursa (job #1707121) | Cod sursa (job #794813)
Cod sursa(job #794813)
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
#include <cstdio>
#include <algorithm>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
vector<int> adj[4000];
vector< pair< int , pair< int , int> > > cutii;
int cost[4000];
bool finished[4000];
int t;
int n;
int tree[3500][3500];
int query(int x, int y) {
int sum = 0;
for (int a=x; a >= 0; a = (a & (a + 1)) - 1)
for (int b=y; b >= 0; b = (b & (b + 1)) - 1)
sum += tree[a][b];
return sum;
}
// Increases value of k-th element by inc.
void set(int x, int y) {
for (int k = x; k < n; k |= k + 1)
{
for (int kk=y; kk < n; kk |= kk + 1)
tree[k][kk]++;
}
}
void unset(int x, int y) {
for (int k = x; k < n; k |= k + 1)
{
for (int kk=y; kk < n; kk |= kk + 1)
tree[k][kk]--;
}
}
int main()
{
fin >> n >> t;
for (int tests=0; tests<t; tests++)
{
cutii.clear();
for (int i=0; i<n; i++)
{
int a,b,c;
fin >> a >> b >> c;
cutii.push_back( make_pair(a,make_pair(b,c)) );
}
sort(cutii.begin(),cutii.end());
int maximal =0;
for (int i=0; i<n; i++)
{
maximal = max(maximal,query(cutii[i].second.first-1,cutii[i].second.second-1));
set(cutii[i].second.first,cutii[i].second.second);
}
for (int i=0; i<n; i++)
unset(cutii[i].second.first,cutii[i].second.second);
fout << maximal+1<<endl;
}
}