Cod sursa(job #164502)

Utilizator ProtomanAndrei Purice Protoman Data 24 martie 2008 12:45:17
Problema Marbles Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define mx 100010

using namespace std;

struct bila
{
	long l,c;
} v[mx];
long a[mx][75];
long i,j,tip,x,y,n,m;
 
inline bool cmp(const bila &a, const bila &b)
{
	return (a.l<b.l);
}

//long cauta(long p, long u, long x)
//{
//	int m=(p+u)/2;
//	if (v[m].l==x)
//		return m;
//	else if (v[m].l>x)
//			return cauta(p,m-1,x);
//		else return cauta(m+1,u,x);
//}

//void add(long x, long y)
//{
//	v[cauta(1,n,x)].l+=y;
//}

long search(long p, long u, long x)
{
	int m=(p+u)/2;
	if (v[m].l<x && v[m+1].l>=x)
		return m;
	else if (v[m].l>x)
			return search(p,m-1,x);
		else return search(m+1,u,x);
}

long maxbila(long x, long y)
{
	int max=0,aux;
	if (x>y)
	{
		aux=x;
		x=y;
		y=aux;
	}
	int s1=search(1,n,x);
	int s2=search(1,n,y+1);
	for (int i=1; i<=64; i++)
		if (a[s2][i]-a[s1][i]>max)
			max=a[s2][i]-a[s1][i];
	return max;
}

int main()
{	
	freopen("marbles.in","r",stdin);
	freopen("marbles.out","w",stdout);
	scanf("%ld %ld",&n,&m);
	for (i=1; i<=n; i++)
		scanf("%ld %ld",&v[i].l,&v[i].c);
	sort(v+1,v+n+1,cmp);
	v[0].l=-LONG_MAX;
	v[n+1].l=v[0].l;
	for (i=1; i<=n; i++)
	{
		for (j=1; j<=64; j++)
			a[i][j]=a[i-1][j];
		a[i][v[i].c]++;
	}
	for (j=1; j<=m; j++)
	{
		scanf("%ld %ld %ld",&tip,&x,&y);
		if (tip==1)
			//add(x,y);
		printf("%ld\n",maxbila(x,y));
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}