Cod sursa(job #2989916)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 7 martie 2023 11:39:41
Problema Marbles Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>

using namespace std;

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

const int kC = 64;
vector<int> pos[kC];

void maxSelf(int &x, int y) {
  if (x < y) {
    x = y;
  }
}

void update(int i, int j) {
  for (auto &vec : pos) {
    auto it = lower_bound(vec.begin(), vec.end(), i);

    if (it != vec.end() && *it == i) {
      *it += j;
      break;
    }
  }
}

int query(int l, int r) {
  int res = 0;

  for (auto vec : pos) {
    maxSelf(res, distance(lower_bound(vec.begin(), vec.end(), l), upper_bound(vec.begin(), vec.end(), r)));
  }

  return res;
}

int main() {
  int n, q;
  fin >> n >> q;

  for (int i = 0; i < n; ++i) {
    int x, c;
    fin >> x >> c;

    pos[c - 1].emplace_back(x);
  }

  for (auto &vec : pos) {
    sort(vec.begin(), vec.end());
  }

  for (int qq = 0; qq < q; ++qq) {
    int op, i, j;
    fin >> op >> i >> j;

    if (op == 0) {
      update(i, j);
    } else {
      fout << query(i, j) << '\n';
    }
  }

  fin.close();
  fout.close();

  return 0;
}