Pagini recente » Cod sursa (job #2500448) | Cod sursa (job #2764784) | Cod sursa (job #2384754) | Cod sursa (job #119957) | Cod sursa (job #1005783)
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
const int NMAX = 100010, ColorMAX = 65;
int N, M, Type, A, B, Freq[NMAX][ColorMAX], V[NMAX];
void Update(int i, int j)
{
int Left = 1, Right = N, Mid;
while(Left <= Right)
{
Mid = (Left + Right) / 2;
if(V[Mid] == i)
{
V[Mid] += j;
return ;
}
if(V[Mid] < i) Left = Mid + 1;
else Right = Mid - 1;
}
}
int Query(int i, int j)
{
int Left = 1, Right = N, Mid, PosBeforeI = 0, PosBeforeJ = 0;
while(Left <= Right)
{
Mid = (Left + Right) / 2;
if(V[Mid] < i) PosBeforeI = Mid, Left = Mid + 1;
else Right = Mid - 1;
}
Left = 1, Right = N;
while(Left <= Right)
{
Mid = (Left + Right) / 2;
if(V[Mid] <= j) PosBeforeJ = Mid, Left = Mid + 1;
else Right = Mid - 1;
}
int Max = 0;
for(int k = 1; k <= 64; ++ k)
Max = max(Max, Freq[PosBeforeJ][k] - Freq[PosBeforeI][k]);
return Max;
}
int main()
{
freopen("marbles.in", "r", stdin);
freopen("marbles.out", "w", stdout);
scanf("%i %i", &N, &M);
for(int i = 1; i <= N; ++ i)
{
scanf("%i %i", &V[i], &B);
for(int j = 1; j <= 64; ++ j)
Freq[i][j] = Freq[i - 1][j];
Freq[i][B] ++;
}
for(int i = 1; i <= M; ++ i)
{
int Type, X, Y;
scanf("%i %i %i", &Type, &X, &Y);
if(Type == 0) Update(X, Y);
else printf("%i\n", Query(X, Y));
}
return 0;
}