Cod sursa(job #3277220)

Utilizator GabrielPopescu21Silitra Gabriel - Ilie GabrielPopescu21 Data 15 februarie 2025 13:55:46
Problema Marbles Scor 0
Compilator cpp-64 Status done
Runda vs11_12_vine_oji_2025 Marime 1.4 kb
#include <bits/stdc++.h>
using namespace std;

const int MAX = 64;
vector<int> colors[MAX];

int main()
{
    ifstream cin("marbles.in");
    ofstream cout("marbles.out");
    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; ++i)
    {
        int coord, color;
        cin >> coord >> color;
        colors[color].push_back(coord);
    }

    for (int i = 1; i <= MAX; ++i)
        sort(colors[i].begin(), colors[i].end());

    for (int i = 1; i <= k; ++i)
    {
        int type, x, y;
        cin >> type >> x >> y;

        if (type == 0)
        {
            for (int j = 1; j <= 64; ++j)
            {
                auto pos = lower_bound(colors[j].begin(), colors[j].end(), x);
                if (pos != colors[j].end())
                {
                    colors[j].erase(pos);

                    auto findPos = lower_bound(colors[j].begin(), colors[j].end(), x+y);
                    colors[j].insert(findPos, x+y);
                }
            }
        }
        else
        {
            int ans = 0;
            for (int j = 1; j <= 64; ++j)
            {
                auto pos1 = lower_bound(colors[j].begin(), colors[j].end(), x);
                auto pos2 = upper_bound(colors[j].begin(), colors[j].end(), y);
                ans = max(ans, (int)(pos2-pos1));
            }
            cout << ans << "\n";
        }
    }

    return 0;
}