ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 1623-B
    코드포스 2021. 12. 29. 20:40
     

    Problem - B - Codeforces

     

    codeforces.com

     

     

    풀이

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    #include <bits/stdc++.h>
    #define endl "\n"
    #define ooop(i, n) for(int i = 0; i < n; i++)
    #define loop(i, n) for(int i = 1; i <= n; i++)
    #define all(v) (v).begin(), (v).end()
     
    using namespace std;
    typedef long long ll;
    typedef pair<intint> pi;
    typedef pair<ll, ll> pl;
     
    struct info{
        int l;
        int r;
        int d;
    };
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        int t; cin >> t;
        while(t--){
            int n; cin >> n;
            vector<int> cnt(n);
            stack<pi> st;
            ooop(i, n){
                int s, e; cin >> s >> e;
                st.push({s, e});
                for(int j = s; j <= e; j++) cnt[j-1]++;
            }
     
            priority_queue<pi, vector<pi>, greater<> > pq;
            ooop(i, n) pq.push({cnt[i], i+1});
     
            vector<info> res;
            while(!pq.empty()){
                auto [_, d] = pq.top(); pq.pop();
                stack<pi> tmp;
                int is = 0, ie = -1;
                while(!st.empty()){
                    auto [s, e] = st.top(); st.pop();
                    if(s <= d && d <= e && ie - is < e - s){
                        if(ie != -1) tmp.push({is, ie});
                            ie = e; is = s;
                    }
                    else tmp.push({s, e});
                }
                res.push_back(info{is, ie, d});
                st = tmp;
            }
     
            for(auto [l, r, d]: res) cout << l << ' ' << r << ' ' << d << endl;
        }
     
        return 0;

    '코드포스' 카테고리의 다른 글

    1622-C  (0) 2021.12.29
    1623-C  (0) 2021.12.29
    1622-B  (0) 2021.12.29
    1303-D, *1900  (0) 2021.12.26
    1303-C, *1600  (0) 2021.12.26

    댓글

Designed by Tistory.