Pagini recente » Cod sursa (job #593597) | Cod sursa (job #2886156) | Cod sursa (job #940862) | Cod sursa (job #892342) | Cod sursa (job #2517999)
#include <iostream>
#include <fstream>
#include <algorithm>
#define dim 1000005
using namespace std;
ifstream fin("marbles.in");
ofstream fout("marbles.out");
int n,s[70][dim],m,i,j,colormax,tip,a,b;
pair<int,int> v[dim];
void gaseste(int a,int b){
int st=1,dr=n;
while(st<=dr){
int mid=(dr-st)/2+st;
if(v[mid].first<a)
st=mid+1;
else if(v[mid].first>a)
dr=mid-1;
else {
v[mid].first+=b;
return;
}
}
}
int pozitie(int x){
int st=1;
int dr=n;
while(st<=dr){
int mid=(dr-st)/2+st;
if(v[mid].first<x)
st=mid+1;
else dr=mid-1;
}
return st;
}
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++){
fin>>v[i].first>>v[i].second;
colormax=max(colormax,v[i].second);
}
sort(v+1,v+n+1);
for(i=1;i<=n;i++)
for(j=1;j<=colormax;j++){
s[j][i]=s[j][i-1];
if(v[i].second==j) s[j][i]++;
}
for(i=1;i<=m;i++){
fin>>tip>>a>>b;
if(tip==0)
gaseste(a,b);
else {
int pozst=pozitie(a);
int pozdr=pozitie(b+1)-1;
int diff=0;
for(j=1;j<=colormax;j++){
diff=max(diff, s[j][pozdr]-s[j][pozst]);
}
fout<<diff<<"\n";
}
}
}