Cod sursa(job #3276947)

Utilizator CimpoesuFabianCimpoesu Fabian George CimpoesuFabian Data 15 februarie 2025 10:35:57
Problema Marbles Scor 100
Compilator cpp-64 Status done
Runda vs11_12_vine_oji_2025 Marime 1.25 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("marbles.in");
ofstream fout("marbles.out");

/**
*/

struct bila
{
    int x,c;
};
bila v[100001];

bool cmp (const bila &a,const bila &b)
{
    return a.x<b.x;
}

int n, i, j, cmax, poz, poz1, poz2, sol, ch, a, b, t, q, s[100001][65];

int cb (int x)
{
    int st = 1, dr = n, mij;
    while (st <= dr)
    {
        mij = (st+dr) / 2;
        if (v[mij].x > x)
            dr = mij - 1;
        else
            st = mij + 1;
    }
    return dr;
}
int main()
{
    fin >> n >> q;
    for (i = 1 ; i <= n ; i++)
    {
        fin >> v[i].x >> v[i].c;
        cmax = max(cmax, v[i].c);
    }
    sort (v+1,v+n+1,cmp);
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=cmax; j++)
            s[i][j]=s[i-1][j];
        s[i][v[i].c]++;
    }
    for (t=1; t<=q; t++)
    {
        fin>>ch>>a>>b;
        if (ch==0)
        {
            poz=cb (a);
            v[poz].x+=b;
        }
        else
        {
            poz1=cb (a-1);
            poz2=cb (b);
            poz1++;
            sol=0;
            for (j=1; j<=cmax; j++)
                sol=max (sol,s[poz2][j]-s[poz1-1][j]);
            fout<<sol<<"\n";
        }
    }
    return 0;
}