Pagini recente » Cod sursa (job #2803015) | Cod sursa (job #2430752) | Cod sursa (job #630360) | Cod sursa (job #3122536) | Cod sursa (job #2549501)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream cin("marbles.in");
ofstream cout("marbles.out");
vector<int> s[70];
int bound(int cul, int pz, int which){
int st = 0;
int dr = s[cul].size() - 1;
int bs = 0;
while(st <= dr){
int mij = (st + dr) / 2;
if(s[cul][mij] <= pz){
bs = mij;
st = mij + 1;
}
else dr = mij - 1;
}
if(!which){
if(s[cul][bs] < pz)
++bs;
}
return bs;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; ++i){
int x, cul;
cin >> x >> cul;
s[cul].push_back(x);
}
for(int i = 1; i <= 64; ++i)
sort(s[i].begin(), s[i].end());
for(int i = 1; i <= m; ++i){
int t, xi, xj;
cin >> t >> xi >> xj;
int lgMax = 0;
for(int cul = 1; cul <= 64; ++cul)
if(s[cul].size() > 0)
if(t == 0){
int pz = bound(cul, xi, 0);
if(s[cul][pz] == xi)
s[cul][pz] += xj;
}
else if(t == 1){
int st = bound(cul, xi, 0);
int fs = bound(cul, xj, 1);
lgMax = max(lgMax, fs - st + 1);
}
if(t)
cout << lgMax << '\n';
}
return 0;
}