Pagini recente » Cod sursa (job #1630268) | Cod sursa (job #836548) | Cod sursa (job #2250359) | Cod sursa (job #2259931) | Cod sursa (job #3277148)
#include <bits/stdc++.h>
#include <unordered_map>
#define nmax 2000006
#define MOD 666013
#define INF 2012345678
#define ll long long
#define ull unsigned long long
using namespace std;
//#define fin cin
//#define fout cout
ifstream fin("marbles.in");
ofstream fout("marbles.out");
/**
pozitiile culorile
set <int> v[67];
adaug fiecare pozitie pt fiecare culoare
tasks:
0:
caut ce culoare are bila de pe pozitia respectiva
scot pozitia anterioara si adaug pozitia noua
1:
caut binar pt fiecare culoare
1) cea mai din stanga pozitie a.i. v[color][mij] >= x
2) cea mai din dreapta pozitie a.i. v[color][mij] <= y
rezultatu e pRight - pLeft + 1
**/
int n, m;
set <int> v[67];
int SearchColor(int p)
{
for (int i = 1; i <= 64; i++)
if (v[i].find(p) != v[i].end()) // daca l gaseste
return i;
return 0; // daca nu l gaseste
}
// 1) cea mai din stanga pozitie a.i. v[color][pLeft] >= x
int CautBin1(int x, int color)
{
auto it = v[color].lower_bound(x);
if (it != v[color].end())
return distance(v[color].begin(), it);
return -1;
}
// 2) cea mai din dreapta pozitie a.i. v[color][pRight] <= y
int CautBin2(int x, int color)
{
auto it = v[color].upper_bound(x);
if (it != v[color].begin())
{
--it;
return std::distance(v[color].begin(), it);
}
return -1;
};
int main()
{
int i, t, x, y, c, pLeft, pRight, maxi, color;
fin >> n >> m;
for (i = 1; i <= n; i++)
{
fin >> x >> y;
v[y].insert(x);
}
for (i = 1; i <= m; i++)
{
fin >> t >> x >> y;
if (t == 0)
{
c = SearchColor(x);
v[c].erase(x);
v[c].insert(x + y);
}
else if (t == 1)
{
maxi = -INF;
for (color = 1; color <= 64; color++)
if (!v[color].empty())
{
pLeft = CautBin1(x, color);
pRight = CautBin2(y, color);
/*if (pLeft == -1 || pRight == -1)
fout << color << " x \n";
else
fout << color << " " << pLeft << " " << pRight << "\n";*/
maxi = max(maxi, pRight - pLeft + 1);
}
fout << maxi << "\n";
//fout << "\n\n";
}
}
return 0;
}