Cod sursa(job #3277141)

Utilizator inacioataCioata Ana Irina inacioata Data 15 februarie 2025 12:47:29
Problema Marbles Scor 0
Compilator cpp-64 Status done
Runda vs11_12_vine_oji_2025 Marime 1.15 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("n.in");
ofstream fout("n.out");
int n, m, a[100003][65];
pair<int, short> b[100003];

int CB(int x)
{
    int st = 1, dr = n, mij, poz = 0;
    while(st <= dr)
    {
        mij = (st + dr) / 2;
        if(b[mij].first <= x)
        {
            poz = mij;
            st = mij + 1;
        }
        else dr = mij - 1;
    }
    return poz;
}

int main()
{
    int i, j, maxx = 0, op, x, y, poz1, poz2;
    fin >> n >> m;
    for(i = 1; i <= n; i++)
        fin >> b[i].first >> b[i].second;

    sort(b + 1, b + n + 1);
    for(i = 1; i <= n; i++)
        a[i][b[i].second]++;

    for(i = 1; i <= n; i++)
        for(j = 1; j <= 64; j++)
            a[i][j] += a[i-1][j];

    for(i = 1; i <= m; i++)
    {
        fin >> op >> x >> y;
        if(op == 0)
        {
            poz1 = CB(x);
            b[poz1].first += y;
            continue;
        }
        poz1 = CB(x - 1);
        poz2 = CB(y);
        maxx = 0;
        for(j = 1; j <= 64; j++)
            maxx = max(maxx, a[poz2][j] - a[poz1][j]);
        fout << maxx << "\n";
    }
    return 0;
}