Pagini recente » Cod sursa (job #1897634) | Cod sursa (job #1355193) | Cod sursa (job #1289243) | Cod sursa (job #1999973) | Cod sursa (job #2847611)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("marbles.in");
ofstream fout("marbles.out");
int n, m, col;
int a[64][100003];
int len[64];
void Citire()
{
int i, c, x;
fin >> n >> m;
for (i = 1; i <= n; i++)
{
fin >> x >> c;
a[c][++len[c]] = x;
col = max(col, c);
}
}
int CautBinMME(int color, int poz)
{
int st, dr, p = 0, mij;
st = 1;
dr = len[color];
while (st <= dr)
{
mij = (st + dr) / 2;
if (a[color][mij] == poz) return mij;
if (a[color][mij] < poz)
st = mij + 1;
else
{
dr = mij - 1;
p = mij;
}
}
return p;
}
int CautBinmmEg(int color, int poz)
{
int st, dr, p = 0, mij;
st = 1;
dr = len[color];
while (st <= dr)
{
mij = (st + dr) / 2;
if (a[color][mij] == poz) return mij;
if (a[color][mij] < poz)
{
p = mij;
st = mij + 1;
}
else dr = mij - 1;
}
return p;
}
void CautBinMax_p1(int x, int y)
{
int i, st, dr, maxs = 0;
for (i = 1; i <= col; i++)
{
st = CautBinMME(i, x);
dr = CautBinmmEg(i, y);
maxs = max(maxs, dr - st + 1);
}
fout << maxs << "\n";
}
void Schimb(int x, int y)
{
int i, poz = 0;
for (i = 1; i <= col; i++)
{
poz = CautBinmmEg(i, x);
if (a[i][poz] == x)
{
a[i][poz] += y;
return;
}
}
}
void Rezolva()
{
int i, j, t, x, y;
for (i = 1; i <= col; i++)
sort(a[i] + 1, a[i] + len[i] + 1);
for (i = 1; i <= m; i++)
{
fin >> t >> x >> y;
if (t == 1)
CautBinMax_p1(x, y);
else
Schimb(x, y);
}
}
int main()
{
Citire();
Rezolva();
return 0;
}