Pagini recente » Cod sursa (job #1093080) | Cod sursa (job #762440) | Cod sursa (job #2709095) | Cod sursa (job #2686749) | Cod sursa (job #2847712)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("marbles.in");
ofstream fout("marbles.out");
int n,m,a,b,t,i,j;
set <int> pos[65];
map <int,int> c;
int main()
{
fin>>n>>m;
for(int i=1; i<=n; i++)
{
fin>>a>>b;
c[a]=b;
pos[b].insert(a);
}
while(m--)
{
fin>>t>>i>>j;
if(t==0)
{
int color=c[i];
pos[color].erase(i);
pos[color].insert(i+j);
c[i]=0;
c[i+j]=color;
}
else
{
int maxim=0;
for(int color=1; color<=64; color++)
{
if(pos[color].empty()) continue;
set <int>::iterator it1=pos[color].lower_bound(i);
set <int>::iterator it2=pos[color].upper_bound(j);
set <int>::iterator it3=it2;
it2--;
if((*it1)<=(*it2))
maxim=max(maxim,(int)distance(it1,it3));
}
fout<<maxim<<"\n";
}
}
return 0;
}