Pagini recente » Cod sursa (job #2487023) | Cod sursa (job #3140886) | Cod sursa (job #2636164) | Cod sursa (job #3233918) | Cod sursa (job #851080)
Cod sursa(job #851080)
#include<cstdio>
#include<algorithm>
#define N 1<<17
#define NRC 65
using namespace std;
struct bila
{
int x,c;
};
bila a[N];
int n,m,d[N][NRC];
bool comp(const bila &A,const bila &B)
{
return (A.x<B.x);
}
void read()
{
freopen("marbles.in","r",stdin);
freopen("marbles.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].c);
}
void init()
{
sort(a+1,a+n+1,comp);
for(int i=1;i<=n;i++)
{
d[i][a[i].c]++;
for(int j=1;j<NRC;j++)
d[i][j]+=d[i-1][j];
}
}
int cautb(int nb)
{
int pas=1<<16,i=0;
for(i=0;pas;pas>>=1)
if(i+pas<=n && a[i+pas].x<=nb)
i+=pas;
return i;
}
void move(int x,int y)
{
int poz=cautb(x);
a[poz].x=x+y;
}
void interogare(int x,int y)
{
int poz1=cautb(x-1);
int poz2=cautb(y);
int maxim=-1;
for(int i=1;i<NRC;i++)
if(d[poz2][i]-d[poz1][i]>maxim)
maxim=d[poz2][i]-d[poz1][i];
printf("%d\n",maxim);
}
void solve()
{
int tip,x,y;
for(;m>=1;m--)
{
scanf("%d%d%d",&tip,&x,&y);
if(tip==1)
interogare(x,y);
else
move(x,y);
}
}
int main()
{
read();
init();
solve();
return 0;
}