Cod sursa(job #2892700)

Utilizator euyoTukanul euyo Data 23 aprilie 2022 11:42:45
Problema Marbles Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int MAXC = 65;

vector<int> pos[MAXC];

inline int count_range( int x, int y, int c ) {
  int l = lower_bound( pos[c].begin(), pos[c].end(), x ) - pos[c].begin();
  int r = upper_bound( pos[c].begin(), pos[c].end(), y ) - pos[c].begin();
  return r - l;
}

int main() {
  int n, m, x, y, c;

  fin >> n >> m;
  for ( int i = 1; i <= n; ++i ) {
    fin >> x >> c;
	pos[c].push_back(x);
  }
  for ( int i = 1; i < MAXC; ++i ) {
	sort(pos[i].begin(), pos[i].end());
  }
  while ( m-- ) {
	fin >> c >> x >> y;
	if ( c == 0 ) {
      for ( int i = 1; i < MAXC; ++i ) {
	    int p = lower_bound( pos[i].begin(), pos[i].end(), x ) - pos[i].begin();
		if ( p < pos[i].size() && pos[i][p] == x ) {
          pos[i][p] = x + y;
		}
	  }
	} else {
	  int res = 0;
	  for ( int i = 1; i < MAXC; ++i ) {
        res = max(res, count_range(x, y, i));
	  }
	  fout << res << "\n";
	}
  }
  fin.close();
  fout.close();
  return 0;
}