Pagini recente » Cod sursa (job #2758884) | Cod sursa (job #161411) | Cod sursa (job #1544032) | Cod sursa (job #2633186) | Cod sursa (job #161159)
Cod sursa(job #161159)
#include <cstdio>
#include <cassert>
#define INF 2000000000
#define MAXN 100005
#define MAXC 64
int N, M;
int X[MAXN], C[MAXN];
int S[MAXN][MAXC];
inline int max(int a, int b) { return (a > b ? a : b); }
int search(int a) {
int st = 0, dr = N, mij;
while (st != dr) {
mij = (st + dr + 1) / 2;
if (X[mij] <= a) st = mij;
else dr = mij-1;
}
return st;
}
int main() {
freopen("marbles.in", "r", stdin);
freopen("marbles.out", "w", stdout);
assert(scanf("%d %d", &N, &M) == 2);
assert(1 <= N && N <= 100000);
assert(1 <= M && M <= 100000);
for (int i = 1; i <= N; ++i) {
assert(scanf("%d %d", X+i, C+i) == 2);
assert(1 <= C[i] && C[i] <= 64);
}
X[0] = -INF;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j < MAXC; ++j)
S[i][j] = S[i-1][j];
++S[i][C[i]-1];
}
for (int i = 0; i < M; ++i) {
int op, a, b;
assert(scanf("%d %d %d", &op, &a, &b) == 3);
continue;
if (op == 0) {
int poz = search(a);
assert(X[poz] == a);
X[poz] += b;
}
else {
int p1 = search(a);
int p2 = search(b);
if (p1 && X[p1] == a) --p1;
int best = 0;
for (int j = 0; j < MAXC; ++j)
best = max(best, S[p2][j] - S[p1][j]);
printf("%d\n", best);
}
}
}