Pagini recente » Cod sursa (job #22514) | Cod sursa (job #219932) | Diferente pentru implica-te/arhiva-educationala intre reviziile 102 si 223 | Cod sursa (job #1282777) | Cod sursa (job #3277054)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("marbles.in");
ofstream fout("marbles.out");
int n , m;
vector<int> L[64];
unordered_map<int , int> M;
int CautBin(int lun , int x)
{
int st = 0 , dr , mij;
dr = L[lun].size() - 1;
while(st <= dr)
{
mij = (st + dr) / 2;
if(L[lun][mij] == x) return mij;
if(L[lun][mij] < x) st = mij + 1;
else dr = mij - 1;
}
return -1;
}
int CautBin1(int lun , int x)
{
int st = 0 , dr , mij , p;
dr = L[lun].size() - 1;
p = L[lun].size();
while(st <= dr)
{
mij = (st + dr) / 2;
if(L[lun][mij] >= x)
{
p = mij;
dr = mij - 1;
}
else st = mij + 1;
}
return p;
}
int CautBin2(int lun, int x)
{
int st = 0 , dr , mij , p = -1;
dr = L[lun].size() - 1;
while(st <= dr)
{
mij = (st + dr) / 2;
if(L[lun][mij] <= x)
{
p = mij;
st = mij + 1;
}
else dr = mij - 1;
}
return p;
}
int main()
{
int i , poz , cul , task , x , y , mx , poz1 , poz2 , k , cnt;
fin >> n >> m;
for (i = 1; i <= n; i++)
{
fin >> poz >> cul;
cul--;
L[cul].push_back(poz);
M[poz] = cul;
}
for(i = 0; i < 64; i++)
sort(L[i].begin(), L[i].end());
for(i = 1; i <= m; i++)
{
fin >> task >> x >> y;
if(task == 0)
{
if(M.find(x) != M.end())
{
cul = M[x];
k = CautBin(cul, x);
if(k != -1)
L[cul][k] = x + y;
M.erase(x);
M[x + y] = cul;
}
}
else if(task == 1)
{
mx = 0;
for(cul = 0; cul < 64; cul++)
{
poz1 = CautBin1(cul, x);
poz2 = CautBin2(cul, y);
cnt = 0;
if (poz1 < L[cul].size() and poz2 >= 0 and poz2 >= poz1)
cnt = poz2 - poz1 + 1;
mx = max(mx, cnt);
}
fout << mx << "\n";
}
}
return 0;
}