44482023-03-28 10:39:41semmiÁdám és Éva együttcpp17Wrong answer 10/5012ms4952 KiB
#include <bits/stdc++.h>
using namespace std;
//using namespace std::chrono;

#define pii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vvi vector<vi>
#define vvb vector<vb>
#define vvl vector<vl>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fScan {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define REP(i, n) for(int i = 0;i <(n); i++)
using ll = long long;
using ld = long double;
ll mod = 1000000007;

const char ny =  '\n';

bool prime(ll a) {
    if (a==1) return 0;
    for (int i=2;i*i<=a;++i)
    {
        if (a%i==0) return 0;
    }
    return 1;
}

ll gcd(ll a,ll b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

ll min(int a, ll b) {
    if(a< b) return a;
    else return b;
}


void solve() { 
        int n;
        cin >> n;
        int a, b;
        cin >> a;
        vector<pair<int ,int>> adam(a+1);
        for(int i = 0;i < a;i++ ) {
            int c, d;
            cin >> c >> d;
            adam[i] = {c, d};
        }
        cin >> b;
        vector<pair<int , int>> eva(b+1);
        for(int i = 0;i < b;i++ ) {
            int c, d;
            cin >> c >> d;
            eva[i] = {c,d};
        }
        eva[b] = {INT_MAX, INT_MAX};
        int most = 0;
        vector<pair<int, int>> ans;

        for(int i = 0;i < a;i++) {
            if(adam[i].second <= eva[most].first) {
                most--;
                //cout << adam[i].second << ' ' << eva[most].first << endl;
            }
            while(adam[i].second > eva[most].first && eva[most].second > adam[i].first) {
                ans.push_back({max(adam[i].first, eva[most].first), min(adam[i].second, eva[most].second)});
                most++;
            }
        }


        cout << ans.size() << endl;
        for(int i = 0;i < ans.size();i++ ) {
            cout << ans[i].first << ' ' << ans[i].second << endl;
        }
    }


int main()
{
    fScan

    int t = 1;
    //comment out if necessary
    //cin>> t;


    //auto start = high_resolution_clock::now();
    while(t-- ) {
        solve();
    }
    //auto end = high_resolution_clock::now();
    //auto dur = duration_cast<milliseconds>(end-start);
    //cout<< "runtime: " << dur.count() << " milliseconds" << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1824 KiB
2Wrong answer0/03ms2016 KiB
3Accepted2/22ms2104 KiB
4Accepted2/23ms2228 KiB
5Accepted2/22ms2468 KiB
6Accepted2/23ms2676 KiB
7Accepted2/22ms2756 KiB
8Wrong answer0/23ms2740 KiB
9Wrong answer0/22ms2736 KiB
10Wrong answer0/23ms2968 KiB
11Wrong answer0/23ms3080 KiB
12Wrong answer0/23ms3164 KiB
13Wrong answer0/23ms3288 KiB
14Wrong answer0/23ms3372 KiB
15Wrong answer0/23ms3508 KiB
16Wrong answer0/210ms4236 KiB
17Wrong answer0/310ms4540 KiB
18Wrong answer0/39ms4488 KiB
19Wrong answer0/410ms4468 KiB
20Wrong answer0/412ms4744 KiB
21Wrong answer0/410ms4824 KiB
22Wrong answer0/410ms4952 KiB