107062024-04-10 09:42:49szilFőnökszámcpp17Accepted 100/100275ms66028 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 200'001;

set<int> a;
multiset<int> b[MAXN];
int vx[MAXN], vy[MAXN];
int curr = 0;

void del(int x, int y) {
    auto it = a.lower_bound(x);
    while (it != a.begin()) {
        it--;
        int val = *it;
        auto it2 = b[val].begin();
        while (it2 != b[val].end() && (*it2) < y) {
            curr--;
            it2 = b[val].erase(it2);
        }
        if (b[val].empty()) {
            a.erase(val);
            it = a.lower_bound(x);
        } else {
            break;
        }
    }
}

void insert(int x, int y) {
    curr++;
    a.insert(x);
    b[x].insert(y);
}

void add(int x, int y) {
    auto it = a.upper_bound(x);
    if (it == a.end()) {
        insert(x, y);
    } else {
        int val = *it;
        if ((*b[*it].rbegin()) <= y) {
            insert(x, y);
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> comp;
    for (int i = 1; i <= n; i++) {
        cin >> vx[i] >> vy[i];
        comp.emplace_back(vx[i]);
    }
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    for (int i = 1; i <= n; i++) vx[i] = lower_bound(comp.begin(), comp.end(), vx[i])-comp.begin();
    for (int i = 1; i <= n; i++) {
        del(vx[i], vy[i]);
        add(vx[i], vy[i]);
        cout << curr << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted8ms20688 KiB
2Accepted70ms23476 KiB
subtask25/5
3Accepted10ms21092 KiB
4Accepted9ms21044 KiB
5Accepted9ms21356 KiB
6Accepted14ms21876 KiB
subtask310/10
7Accepted8ms21760 KiB
8Accepted10ms22060 KiB
9Accepted10ms21916 KiB
10Accepted10ms22300 KiB
11Accepted10ms22492 KiB
12Accepted9ms22780 KiB
13Accepted13ms22728 KiB
14Accepted13ms23036 KiB
subtask410/10
15Accepted10ms22880 KiB
16Accepted9ms23036 KiB
17Accepted10ms22936 KiB
18Accepted12ms23084 KiB
19Accepted14ms23364 KiB
20Accepted20ms23852 KiB
21Accepted19ms23808 KiB
22Accepted71ms34724 KiB
subtask525/25
23Accepted8ms23140 KiB
24Accepted10ms23148 KiB
25Accepted12ms23448 KiB
26Accepted13ms23584 KiB
27Accepted39ms24572 KiB
28Accepted54ms25440 KiB
29Accepted68ms25832 KiB
30Accepted67ms25916 KiB
subtask650/50
31Accepted10ms23280 KiB
32Accepted70ms25824 KiB
33Accepted10ms21092 KiB
34Accepted9ms21044 KiB
35Accepted9ms21356 KiB
36Accepted14ms21876 KiB
37Accepted8ms21760 KiB
38Accepted10ms22060 KiB
39Accepted10ms21916 KiB
40Accepted10ms22300 KiB
41Accepted10ms22492 KiB
42Accepted9ms22780 KiB
43Accepted13ms22728 KiB
44Accepted13ms23036 KiB
45Accepted10ms22880 KiB
46Accepted9ms23036 KiB
47Accepted10ms22936 KiB
48Accepted12ms23084 KiB
49Accepted14ms23364 KiB
50Accepted20ms23852 KiB
51Accepted19ms23808 KiB
52Accepted71ms34724 KiB
53Accepted8ms23140 KiB
54Accepted10ms23148 KiB
55Accepted12ms23448 KiB
56Accepted13ms23584 KiB
57Accepted39ms24572 KiB
58Accepted54ms25440 KiB
59Accepted68ms25832 KiB
60Accepted67ms25916 KiB
61Accepted14ms23648 KiB
62Accepted14ms23508 KiB
63Accepted13ms23508 KiB
64Accepted41ms29128 KiB
65Accepted14ms23508 KiB
66Accepted12ms23808 KiB
67Accepted12ms24028 KiB
68Accepted13ms23928 KiB
69Accepted59ms26460 KiB
70Accepted275ms66028 KiB