28252023-01-28 15:33:161478Ádám és Éva együttcpp17Accepted 50/5016ms5744 KiB
#include <bits/stdc++.h>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    fast_cin();
    //ifstream cin("in.txt");

    int maxIntervallEnd;
    cin >> maxIntervallEnd;

    int adamIntervallNum;
    cin >> adamIntervallNum;

    vector<pair<int, int>> adamIntervalls(adamIntervallNum + 1);
    for (int i = 1; i <= adamIntervallNum; i++)
    {
        cin >> adamIntervalls[i].first >> adamIntervalls[i].second;
    }

    int eveIntervallNum;
    cin >> eveIntervallNum;

    vector<pair<int, int>> eveIntervalls(eveIntervallNum + 1);
    for (int i = 1; i <= eveIntervallNum; i++)
    {
        cin >> eveIntervalls[i].first >> eveIntervalls[i].second;
    }

    int adamPointer = 1;
    int evePointer = 1;
    int answersNum = 0;
    vector<pair<int, int>> answers;
    while (adamPointer <= adamIntervallNum && evePointer <= eveIntervallNum)
    {
        int s = max(adamIntervalls[adamPointer].first, eveIntervalls[evePointer].first);
        int f = min(adamIntervalls[adamPointer].second, eveIntervalls[evePointer].second);

        if (f - s >= 1)
        {
            answersNum++;
            answers.push_back({s, f});
        }

        if (adamIntervalls[adamPointer].second < eveIntervalls[evePointer].second)
        {
            adamPointer++;
        }
        else //if (adamIntervalls[adamPointer].second > eveIntervalls[evePointer].second)
        {
            evePointer++;
        }
        /*else
        {
            adamPointer++;
            evePointer++;
        }*/

        //cout << adamPointer << " " << evePointer << '\n';
    }

    cout << answersNum << '\n';
    for (int i = 0; i < answersNum; i++)
    {
        cout << answers[i].first << " " << answers[i].second << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/02ms2020 KiB
3Accepted2/22ms2224 KiB
4Accepted2/22ms2448 KiB
5Accepted2/22ms2672 KiB
6Accepted2/22ms2852 KiB
7Accepted2/22ms2916 KiB
8Accepted2/22ms3008 KiB
9Accepted2/22ms3140 KiB
10Accepted2/22ms3260 KiB
11Accepted2/22ms3468 KiB
12Accepted2/22ms3676 KiB
13Accepted2/22ms3880 KiB
14Accepted2/22ms4088 KiB
15Accepted2/22ms4160 KiB
16Accepted2/214ms5344 KiB
17Accepted3/316ms5348 KiB
18Accepted3/314ms5472 KiB
19Accepted4/414ms5744 KiB
20Accepted4/416ms5540 KiB
21Accepted4/416ms5488 KiB
22Accepted4/416ms5608 KiB