Cod sursa(job #2549505)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 17 februarie 2020 19:08:07
Problema Marbles Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.87 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

	
class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;
 
	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}
 
public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}
 
	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
 
	InParser& operator >> (long long &n) {
		char c;
		n = 0;
		while (!isdigit(c = read_ch()) && c != '-');
		long long sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};

ifstream cin("marbles.in");
ofstream cout("marbles.out");

	
vector<int> s[70];
 
void swap(int &a, int &b){
	a ^= b;
	b ^= a;
	a ^= b;
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
 
	for(int i = 1; i <= n; ++i){
		int x, cul;
		cin >> x >> cul;
 
		s[cul].push_back(x);
	}
 
	for(int i = 1; i <= 64; ++i)
		sort(s[i].begin(), s[i].end());
 
	for(int i = 1; i <= m; ++i){
		int t, xi, xj;
		cin >> t >> xi >> xj;
 
		int lgMax = 0;
		for(int cul = 1; cul <= 64; ++cul)
			if(s[cul].size() > 0)
				if(t == 0){
					int pz = lower_bound(s[cul].begin(), s[cul].end(), xi) - s[cul].begin();
					if(s[cul][pz] == xi)
						s[cul][pz] += xj;
				}
				else if(t == 1){
					int st = lower_bound(s[cul].begin(), s[cul].end(), xi) - s[cul].begin();
					int fs = (upper_bound(s[cul].begin(), s[cul].end(), xj) - 1) - s[cul].begin();
					lgMax = max(lgMax, fs - st + 1);	
				}
		if(t)
			cout << lgMax << '\n';
	}
	return 0;
}