Cod sursa(job #486274)

Utilizator Teodor94Teodor Plop Teodor94 Data 20 septembrie 2010 22:45:18
Problema Marbles Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<cstdio>
#include<algorithm>

using namespace std;

struct marbles
{
	int x,c;
};

bool comp(marbles a,marbles b)
{
	if (a.x<b.x)
		return true;
	return false;
}

const int N=100005;
const int M=66;

int n,m,mat[N][M];
marbles a[N];

void citire()
{
	freopen("marbles.in","r",stdin);
	freopen("marbles.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		scanf("%d%d",&a[i].x,&a[i].c);
	sort(a+1,a+n+1,comp);
	for (int i=1;i<=n;++i)
	{
		mat[i][a[i].c]++;
		for (int j=1;j<M;++j)
			mat[i][j]+=mat[i-1][j];
	}
}

int cautbin(int xx)
{
	int i,pas=1<<16;
	for (i=0;pas;pas>>=1)
		if (i+pas<=n && a[i+pas].x<=xx)
			i+=pas;
	return i;
}

void muta(int xx,int yy)
{
	int poz=cautbin(xx);
	a[poz].x=xx+yy;
}

void interogare(int xx,int yy)
{
	int poz1=cautbin(xx-1),poz2=cautbin(yy),max=-1;
	for (int i=1;i<M;++i)
		if (mat[poz2][i]-mat[poz1][i]>max)
			max=mat[poz2][i]-mat[poz1][i];
	printf("%d\n",max);
}

void rez()
{
	int q,x,y;
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d%d",&q,&x,&y);
		if (q==1)
			interogare(x,y);
		else
			muta(x,y);
	}
}

int main()
{
	citire();
	rez();
	return 0;
}