Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
1.2 kB
4
Indexable
Never
#include<iostream>
#include<set>
using namespace std;
 
struct cmp
{
    bool operator()(pair<int,int> a , pair<int,int> b)
    {
        return a.second < b.second;
    }
};
set<pair<int,int>,cmp> user[101];
 
void init()
{
    for(int i = 1; i<=100;i++)
    {
        user[i].clear();
    }
}
 
void add(int mX, int mY)
{
    user[mX].insert(make_pair(mX+1, mY));
    user[mX+1].insert(make_pair(mX, mY));
}
 
void remove(int mX, int mY)
{
    user[mX].erase(make_pair(mX, mY));
    user[mX+1].erase(make_pair(mX+1, mY));
}
 
int numberOfCross(int mID)
{
    int id = mID;
    int res = 0;
    auto it = user[id].upper_bound(make_pair(mID,0));
    while(it !=user[id].end() )
    {
        res ++;
        auto s = *it;
        id = s.first;
        it = user[id].upper_bound(make_pair(s.first,s.second));
    }
    //cout <<res<<endl;
    return res;
}
 
int participant(int mX, int mY)
{
     
    int id = mX;
    auto it = user[id].lower_bound(make_pair(mX,mY));
    while(it !=user[id].begin() )
    {
        it--;
        auto s = *it;
        id = s.first;
        it = user[id].lower_bound(make_pair(s.first,s.second));
    }
    return id;
}
Leave a Comment