Pagini recente » Cod sursa (job #2167655) | Cod sursa (job #2909467) | Cod sursa (job #2491923) | Cod sursa (job #1261202) | Cod sursa (job #476201)
Cod sursa(job #476201)
#include <cstdio>
#include <cstring>
#include <algorithm>
#define dim 8192
char ax[dim];
int pz;
inline void cit (int &x)
{
x = 0;
int neg = 0;
while ((ax[pz] < '0' || ax[pz] > '9') && ax[pz] != '-')
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
if (ax[pz] == '-')
{
neg = 1;
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
}
while (ax[pz] >= '0' && ax[pz] <= '9')
{
x = x * 10 + ax[pz] - '0';
if (++pz == dim)
fread (ax, 1, dim, stdin), pz = 0;
}
if (neg)
x = -x;
}
using namespace std;
int n, m;
struct nod
{
int x, color;
};
struct cmp
{
bool operator () (const nod &a, const nod &b)const
{
if (a.x < b.x)
return true;
return false;
}
};
nod a[100001];
int nr[65][100001];
void update (int x, int y)
{
int i, cnt;
for (i = 1, cnt = (1 << 17); cnt; cnt >>= 1)
if (i + cnt <= n)
if (a[i + cnt].x <= x)
i += cnt;
if (a[i].x == x)
a[i].x = y;
}
int query (int x, int y)
{
int pi, pj;
int i, cnt;
for (i = n, cnt = (1 << 17); cnt ; cnt >>= 1)
if (i - cnt >= 1)
if (a[i - cnt].x >= x)
i -= cnt;
pi = i;
for (i = 1, cnt = (1 << 17); cnt; cnt >>= 1)
if (i + cnt <= n)
if (a[i + cnt].x <= y)
i += cnt;
pj = i;
int ret = 0;
for (i = 1; i <= 64; ++i)
ret = max (ret, nr[i][pj] - nr[i][pi - 1]);
return ret;
}
int main ()
{
freopen ("marbles.in", "r", stdin);
freopen ("marbles.out", "w", stdout);
cit (n); cit (m);
int i;
for (i = 1; i <= n; ++i)
cit (a[i].x), cit (a[i].color);
sort (a + 1, a + n + 1, cmp ());
for (i = 1; i <= 64; ++i)
{
nr[i][0] = 0;
for (int j = 1; j <= n; ++j)
if (a[j].color == i)
nr[i][j] = nr[i][j - 1] + 1;
else
nr[i][j] = nr[i][j - 1];
}
int tip, p, q;
while (m--)
{
cit (tip); cit (p); cit (q);
if (tip == 0)
update (p, p + q);
else
printf ("%d\n", query (p, q));
}
return 0;
}