Untitled
unknown
plain_text
2 years ago
1.2 kB
8
Indexable
#include <map>
using namespace std;
struct Comparator
{
inline bool operator()(pair<int,int>a1,pair<int,int>a2)
{
return a1.first < a2.first;
}
};
map<int, int> Line[105];
void init()
{
for (int i = 0; i <= 100; i++)
{
Line[i].clear();
}
}
void add(int mX, int mY)
{
Line[mX].insert(make_pair(mY,mX+1));
Line[mX+1].insert(make_pair(mY,mX));
}
void remove(int mX, int mY)
{
Line[mX].erase(mY);
Line[mX+1].erase(mY);
}
int numberOfCross(int mID)
{
int count = 0;
if(!Line[mID].empty())
{
int i = mID;
int r = 0;
auto it = Line[i].upper_bound(r);
while ( it != Line[i].end())
{
count++;
i = it->second;
r = it->first;
it = Line[i].upper_bound(r);
}
}
return count;
}
int participant(int mX, int mY)
{
int r = mY;
int c = mX;
auto it = Line[c].lower_bound(r);
while (it != Line[c].begin() && Line[c].empty() == false)
{
it--;
c = it->second;
r = it->first;
it = Line[c].lower_bound(r);
}
return c;
}
Editor is loading...