Cod sursa(job #1787698)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 24 octombrie 2016 22:05:01
Problema Marbles Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>

using namespace std;

int main()
{
    ifstream in("marbles.in");
    ofstream out("marbles.out");

    vector<pair<int,int>> marbles;
    int N, M;

    in >> N >> M;

    for (int i = 0; i < N; ++i){
        int x, c;
        in >> x >> c;
        marbles.push_back({x, c - 1});
    }

    sort(marbles.begin(), marbles.end());

    auto cmpX = [](const auto &x, const auto &y){
        return x.first < y.first;
    };

    vector<int> counter(64);

    for (int op = 0; op < M; ++op){
        int t, x, y;
        in >> t >> x >> y;

        if (t == 0){
            auto it = lower_bound(marbles.begin(), marbles.end(), make_pair(x, 0), cmpX);
            it->first += y;
        }
        else{
            auto it1 = lower_bound(marbles.begin(), marbles.end(), make_pair(x, 0), cmpX);
            auto it2 = upper_bound(marbles.begin(), marbles.end(), make_pair(y, 0), cmpX);

            assert(it1 != marbles.end());

            fill(counter.begin(), counter.end(), 0);

            while (it1 != it2){
                counter[it1->second]++;
                it1++;
            }

            out << *max_element(counter.begin(), counter.end()) << "\n";
        }
    }

    return 0;
}