Pagini recente » Cod sursa (job #1996916) | Cod sursa (job #3244374) | Cod sursa (job #545829) | Cod sursa (job #3142679) | Cod sursa (job #2989916)
#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;
}