Cod sursa(job #1538053)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 28 noiembrie 2015 14:07:50
Problema Marbles Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <vector>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;

constexpr int maxcul = 64;

struct punct{
	int poz, cul; };

bool operator<(const punct& a, const punct& b){
	return a.poz < b.poz || (a.poz == b.poz && a.cul < b.cul); }

int main(){
	ifstream f("marbles.in");
	ofstream g("marbles.out");
	int n, m;
	f >> n >> m;
	vector<punct> pts(n);
	for(auto& p : pts){
		f >> p.poz >> p.cul;
		--p.cul; }
	sort(begin(pts), end(pts));
	
	vector<array<int, maxcul> > s_part(n+1);
	for(int i = n-1; i >= 0; --i){
		s_part[i] = s_part[i+1];
		++s_part[i][pts[i].cul]; }

	for(int i = 0, t, x, y; i < m; ++i){
		f >> t >> x >> y;
		if(t == 0){
			auto it = lower_bound(begin(pts), end(pts), (punct){ x, 0 });
			it->poz += y; }
		else{
			int st = lower_bound(begin(pts), end(pts), (punct){x, 0}) - begin(pts),
				dr = upper_bound(begin(pts), end(pts), (punct){y, 64}) - begin(pts);
			int rez = 1;
			for(int j = 0; j < maxcul; ++j){
				rez = max(rez, s_part[st][j] - s_part[dr][j]); }
			g << rez << '\n'; } }
	return 0; }