Pagini recente » Cod sursa (job #1165060) | Cod sursa (job #1551968) | Cod sursa (job #1418154) | Cod sursa (job #995461) | Cod sursa (job #1866924)
#include <cstdio>
#include <algorithm>
#define MAXN 100000
#define MAXC 64
int v[MAXN], ml[MAXN], mc[MAXN];
int nr[MAXC][MAXN];
int n;
bool cmp(int a, int b){
if(ml[a] < ml[b])
return 1;
return 0;
}
inline void precalc(){
int i, j;
for(j = 0; j < MAXC; j++){
for(i = 0; i < n; i++){
if(i != 0)
nr[j][i] = nr[j][i - 1];
if(mc[v[i]] == j)
nr[j][i]++;
}
}
}
inline int caut(int x){
int i = -1, pas;
for(pas = (1 << 16); pas > 0; pas /= 2){
if(i + pas < n && ml[v[i + pas]] < x)
i += pas;
}
return i;
}
int main(){
FILE *in = fopen("marbles.in", "r");
int m, t, x, y, ps, pd, rez, rc, i, j, aux;
fscanf(in, "%d%d", &n, &m);
for(i = 0; i < n; i++){
fscanf(in, "%d%d", &ml[i], &mc[i]);
mc[i]--;
v[i] = i;
}
std::sort(v, v + n, cmp);
precalc();
FILE *out = fopen("marbles.out", "w");
for(i = 0; i < m; i++){
fscanf(in, "%d%d%d", &t, &x, &y);
if(t == 0){
ps = caut(x + 1);
ml[v[ps]] += y;
}
else{
if(x > y){
aux = x; x = y; y = aux;
}
ps = caut(x);
pd = caut(y + 1);
rez = 0;
for(j = 0; j < MAXC; j++){
rc = nr[j][pd];
if(ps != -1)
rc -= nr[j][ps];
if(rc > rez)
rez = rc;
}
fprintf(out, "%d\n", rez);
}
}
fclose(in);
fclose(out);
return 0;
}