Cod sursa(job #2517280)

Utilizator lucametehauDart Monkey lucametehau Data 3 ianuarie 2020 12:09:04
Problema Marbles Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

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

int n, q, t, x, y;

vector <int> v[65];
map <int, int> color;

int solve(int x, int col) {
  int poz = upper_bound(v[col].begin(), v[col].end(), x) - v[col].begin();
  return poz;
}

int main() {
  cin >> n >> q;
  for(int i = 1; i <= n; i++) {
    cin >> x >> y;
    v[y].push_back(x);
    color[x] = y;
  }
  for(; q; q--) {
    cin >> t >> x >> y;
    if(t == 0) {
      int poz = lower_bound(v[color[x]].begin(), v[color[x]].end(), x) - v[color[x]].begin();
      v[color[x]][poz] += y;
      color[x + y] = color[x];
      color.erase(x);
    } else {
      int ans = 0;
      for(int i = 1; i <= 64; i++) {
        if(v[i].empty())
          continue;
        ans = max(ans, solve(y, i) - (x == -2147483648 ? 0 : solve(x - 1, i)));
      }
      cout << ans << "\n";
    }
  }
  return 0;
}