Pagini recente » Cod sursa (job #2581013) | Cod sursa (job #406015) | Cod sursa (job #2416294) | Cod sursa (job #2789303) | Cod sursa (job #2533257)
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream in ("marbles.in");
ofstream out ("marbles.out");
const int N = 1e5;
const char CUL = 64;
vector <int> v[5 + CUL];
int cautst(int color, int elem){
int st, dr, mid, ans;
st = 1;
dr = v[color].size() - 1;
ans = dr + 1;
while(st <= dr){
mid = (st + dr) >> 1;
if(v[color][mid] >= elem){
ans = mid;
dr = mid - 1;
} else st = mid + 1;
}
return ans;
}
int cautdr(int color, int elem){
int st, dr, mid, ans(0);
st = 1;
dr = v[color].size() - 1;
while(st <= dr){
mid = (st + dr) >> 1;
if(v[color][mid] <= elem){
ans = mid;
st = mid + 1;
} else dr = mid - 1;
}
return ans;
}
int main()
{
int n, m, culmax(0), i, j, x, c, y, tip, Max;
in >> n >> m;
for(x = 1; x <= CUL; x++) v[x].push_back(0);
for(i = 1; i <= n; i++){
int x, c;
in >> x >> c;
v[c].push_back(x);
culmax = max(culmax, c);
}
for(i = 1; i <= culmax; i++) sort(v[i].begin(), v[i].end());
for(i = 1; i <= m; i++){
Max = 0;
in >> tip >> x >> y;
for(j = 1; j <= culmax; j++){
if(tip == 0){
int pos = cautst(j, x);
if(v[j][pos] == x)
v[j][pos] += y;
} else{
int posst = cautst(j, x);
int posdr = cautdr(j, y);
Max = max(Max, posdr - posst + 1);
}
}
if(tip == 1)
out << Max << '\n';
}
in.close();
out.close();
return 0;
}