Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
975 B
2
Indexable
#include <iostream>
#include <set>
#include <utility>
using namespace std;

set<pair<int,int>> 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 + 1, mY));
    user[mX + 1].erase(make_pair(mX, 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++;
        id = it->first;
        it = user[id].upper_bound(make_pair(id, it->second));
    }
    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--;
        id = it->first;
        it = user[id].lower_bound(make_pair(id, it->second));
    }
    return id;
}
Leave a Comment