Pagini recente » Cod sursa (job #872086) | Cod sursa (job #1019731) | Cod sursa (job #639644) | Cod sursa (job #278555) | Cod sursa (job #2519955)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("marbles.in");
ofstream fout ("marbles.out");
pair <int, int> x[100010];
int m[65][100010];
int n,M,mx,i,j,st,dr,ST,DR,a,b,sol,tip,mid;
void matrice(){
for(int i=1;i<=n;i++)
for(int j=1;j<=mx;j++)
if(x[i].second==j)
m[j][i]=m[j][i-1]+1;
else
m[j][i]=m[j][i-1];
}
int main(){
fin>>n>>M;
for(i=1;i<=n;i++){
fin>>x[i].first>>x[i].second;
mx=max(mx,x[i].second);
}
sort(x+1,x+n+1);
matrice();
for(i=1;i<=M;i++){
fin>>tip>>a>>b;
if(tip==0){
st=1;
dr=n;
while(st<=dr){
mid=st+(dr-st)/2;
if(x[mid].first < a)
st=mid+1;
else
dr=mid-1;
}
x[st].first+=b;
}
else{
st=1;
dr=n;
while(st<=dr){
mid=st+(dr-st)/2;
if(x[mid].first < a)
st=mid+1;
else
dr=mid-1;
}
ST=st;
st=1;
dr=n;
while(st<=dr){
mid=st+(dr-st)/2;
if(x[mid].first <= b)
st=mid+1;
else
dr=mid-1;
}
DR=dr;
sol=0;
for(j=1;j<=mx;j++)
sol=max(sol, m[j][DR]-m[j][ST-1]);
fout<<sol<<"\n";
}
}
return 0;
}