105972024-04-06 12:49:36MagyarKendeSZLGÁdám és Éva együttcpp17Accepted 50/5050ms25668 KiB
// O(A log(A) + E log(A + E))
#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define size(v) (int)v.size()

using namespace std;
using ll = long long;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);

    map<int, vector<pair<char, bool>>> m;
    int P, A, E;
    cin >> P >> A;

    while (A--) {
        int AK, AV;
        cin >> AK >> AV;
        m[AK].push_back({'A', 1});
        m[AV].push_back({'A', 0});
    }

    cin >> E;
    while (E--) {
        int EK, EV;
        cin >> EK >> EV;
        m[EK].push_back({'E', 1});
        m[EV].push_back({'E', 0});
    }

    vector<array<int, 2>> result;

    bool A_free = 0, E_free = 0;
    for (const auto& [t, v] : m) {
        for (auto [c, b] : v) {
            if (c == 'A') {
                A_free = b;
            } else {
                E_free = b;
            }
        }

        if (A_free && E_free) {
            if (result.empty() || result.back()[1] != -1) {
                result.push_back({t, -1});
            }
        } else {
            if (!result.empty() && result.back()[1] == -1) {
                result.back()[1] = t;
            }
        }
    }

    cout << size(result) << "\n";
    for (auto [b, e] : result) cout << b << " " << (e == -1 ? P : e) << "\n";
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/03ms2208 KiB
3Accepted2/23ms2284 KiB
4Accepted2/23ms2516 KiB
5Accepted2/23ms2712 KiB
6Accepted2/22ms2804 KiB
7Accepted2/23ms3016 KiB
8Accepted2/23ms3232 KiB
9Accepted2/23ms3212 KiB
10Accepted2/23ms3124 KiB
11Accepted2/23ms3268 KiB
12Accepted2/23ms3652 KiB
13Accepted2/23ms3384 KiB
14Accepted2/23ms3500 KiB
15Accepted2/23ms3700 KiB
16Accepted2/243ms21188 KiB
17Accepted3/346ms22104 KiB
18Accepted3/341ms21112 KiB
19Accepted4/441ms22416 KiB
20Accepted4/450ms25248 KiB
21Accepted4/445ms25080 KiB
22Accepted4/446ms25668 KiB