Pagini recente » Cod sursa (job #2691232) | Cod sursa (job #595099) | Cod sursa (job #839253) | Cod sursa (job #1561809) | Cod sursa (job #1167076)
#include <fstream>
#include <algorithm>
#define DIM 100010
using namespace std;
pair <int, int> b[DIM];
int s[65][DIM]; //s[i][j] = de cate ori apare culoarea i in
// primele j bile
int n, m, i, j, maxim, st, dr, p, u, mid, k, t;
int main() {
ifstream fin("marbles.in");
ofstream fout("marbles.out");
fin>>n>>m;
for (i=1;i<=n;i++) {
fin>>b[i].first>>b[i].second;
}
sort(b+1, b+n+1);
for (i=1;i<=n;i++) {
for (j=1;j<=64; j++)
if (j == b[i].second)
s[ j ][i] = 1 + s[ j ][i-1];
else
s[j][i] = s[j][i-1];
}
for (k=1;k<=m;k++) {
fin>>t>>i>>j;
if (t == 0) {
// catut pozitia bilei de la coordonata i
// caut binar pe i in vectorul b cu valori first
p = 1;
u = n;
while (p<=u) {
mid = p + (u-p)/2;
if (b[mid].first == i)
break;
if (b[mid].first < i)
p = mid+1;
else
u = mid-1;
}
if (p<=u)
b[mid].first += j;
} else {
// cat e culoarea majoritara intre pozitiile i si j
// caut in b prima pozitie cu valoare >= i
p = 1; u = n;
while (p<=u) {
mid = p + (u-p)/2;
if (b[mid].first < i)
p = mid+1;
else
u = mid-1;
}
st = p;
// caut ultima pozitie cu valoare <= j
p = 1; u = n;
while (p<=u) {
mid = p + (u-p)/2;
if (b[mid].first > j)
u = mid - 1;
else
p = mid+1;
}
dr = u;
maxim = 0;
for (i=1;i<=64; i++)
if (s[i][dr] - s[i][st-1] > maxim)
maxim = s[i][dr] - s[i][st-1];
fout<<maxim<<"\n";
}
}
return 0;
}