Submission #32647023


Source Code Expand

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.06.22 00:58:12
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;


constexpr int INF = 1e9 + 6;

set<pair<int,int>> st;

void insert(int l,int r) {
    auto itl = st.upper_bound({l,INF}), itr = st.upper_bound({r,INF});
    if (itl != st.begin() && (--itl)->second < l) itl++;
    if (itl != itr) {
        l = min(l , itl->first);
        r = max(r, prev(itr)->second);
        st.erase(itl,itr);
    }
    st.insert({l,r});
}

int main() {
    int n;cin >> n;
    for (int i = 0; i < n; i++) {
        int l,r;cin >> l >> r;
        insert(l,r);
    }
    for (auto it = st.begin(); it != st.end(); it++) {
        cout << it->first << " " << it->second << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task D - Union of Interval
User kanpurin
Language C++ (GCC 9.2.1)
Score 400
Code Size 812 Byte
Status AC
Exec Time 180 ms
Memory 6292 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
random_01.txt AC 98 ms 3464 KiB
random_02.txt AC 40 ms 3452 KiB
random_03.txt AC 135 ms 3592 KiB
random_04.txt AC 94 ms 3644 KiB
random_05.txt AC 120 ms 3632 KiB
random_06.txt AC 134 ms 3656 KiB
random_07.txt AC 103 ms 3640 KiB
random_08.txt AC 59 ms 3540 KiB
random_09.txt AC 135 ms 3588 KiB
random_10.txt AC 90 ms 3528 KiB
random_11.txt AC 82 ms 3624 KiB
random_12.txt AC 2 ms 3552 KiB
random_13.txt AC 132 ms 4920 KiB
random_14.txt AC 109 ms 4616 KiB
random_15.txt AC 90 ms 4744 KiB
random_16.txt AC 162 ms 4828 KiB
random_17.txt AC 151 ms 4556 KiB
random_18.txt AC 94 ms 4696 KiB
random_19.txt AC 180 ms 5936 KiB
random_20.txt AC 90 ms 4728 KiB
random_21.txt AC 148 ms 6292 KiB
random_22.txt AC 105 ms 5448 KiB
sample_01.txt AC 6 ms 3592 KiB
sample_02.txt AC 2 ms 3572 KiB