Pagini recente » Cod sursa (job #2550269) | Cod sursa (job #907443) | Cod sursa (job #2245436) | Cod sursa (job #2397302) | Cod sursa (job #205465)
Cod sursa(job #205465)
#include <stdio.h>
#include <algorithm>
using namespace std;
#define maxn 100010
#define maxl 65
#define max(a,b) (a > b ? a : b)
int n, m, sol;
int a[maxn], b[maxn], p[maxn];
int c[maxl][maxn];
int cmp(int x, int y)
{
return a[x] < a[y];
}
int search(int x)
{
int front = 1, middle, back = n, rez = n+1;
while (front <= back)
{
middle = (front + back) / 2;
if (a[p[middle]] <= x)
{
rez = middle;
front = middle + 1;
}
else back = middle - 1;
}
return rez;
}
int main()
{
freopen("marbles.in", "r", stdin);
freopen("marbles.out", "w", stdout);
scanf("%d %d ", &n, &m);
int i, j, x, y, px, py, tip;
for (i=1; i<=n; i++)
{
scanf("%d %d ", &a[i], &b[i]);
p[i] = i;
}
sort(p+1, p+n+1, cmp);
for (i=1; i<=n; i++)
for (j=0; j<maxl; j++)
{
c[i][j] = c[i-1][j];
if (j == b[p[i]]) c[i][j]++;
}
for (i=1; i<=m; i++)
{
scanf("%d %d %d ", &tip, &x, &y);
if (tip == 0)
{
x = search(x);
a[p[x]] += y;
}
else {
px = search(x);
if (a[p[px]] == x) px--;
py = search(y);
sol = 0;
for (j=0; j<maxl; j++) sol = max(sol, c[py][j] - c[px][j]);
printf("%d\n", sol);
}
}
return 0;
}