Cod sursa(job #3277156)

Utilizator alex_0747Gheorghica Alexandru alex_0747 Data 15 februarie 2025 12:58:29
Problema Marbles Scor 60
Compilator cpp-64 Status done
Runda vs11_12_vine_oji_2025 Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_map>
using namespace std;

ifstream fin("marbles.in");
ofstream fout("marbles.out");

vector <int> a[70];
unordered_map <int, int> M;
int n;

int Max(int p, int q)
{
	int mx = 0;
	for (int i = 1; i <= 64; i++)
	{
		int nr = 0;
		for (int e : a[i])
			if (e >= p && e <= q)
				nr++;
		mx = max(mx, nr);
	}
	return mx;
}

int main()
{
	int i, op, x, y, q;
	fin >> n >> q;
	for (i = 1; i <= n; i++)
	{
		fin >> x >> y;
		a[y].push_back(x);
		M[x] = y;
	}

	while (q--)
	{
		fin >> op >> x >> y;
		if (op == 0)
		{
			for (i = 0; i < a[M[x]].size(); i++)
				if (a[M[x]][i] == x)
				{
					a[M[x]][i] += y;
					break;
				}
		}
		else
			fout << Max(x, y) << '\n';
	}
	return 0;
}