Cod sursa(job #2847711)

Utilizator puica2018Puica Andrei puica2018 Data 11 februarie 2022 12:11:01
Problema Marbles Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#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,distance(it1,it3));
            }
            fout<<maxim<<"\n";
        }
    }
    return 0;
}