181392025-10-02 12:04:20ubormaciMekk Mester munkái (50 pont)cpp17Elfogadva 50/5046ms3756 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*
 *
 * notes:
 *
 * int64_t
 * stoi(string s) -> string to int
 * to_string() -> int (or else) to string
 *
 * vector declaration:
 * vector<ll> v(n, 0)
 * vector<vector<ll>> v(n, vector<ll>(n, 0));
 *
 * {if statement} ? {truth value} : {false value}
 *
 * set lower bound/upper bound:
 * 	// . . . m1 . . . d . . . . m2
 *    auto m1_it = b.lower_bound(d);
 *    advance(m1_it, -1);
 *    m1 = *m1_it;
 *	m2 = *b.upper_bound(d);
 *
 * #ifdef LOCAL
 *    freopen("in.txt","r",stdin);
 *    freopen("out.txt","w",stdout);
 * #endif
 *
 * constexpr auto lcm(auto x, auto... xs)
 * {
 *	return ((x = std::lcm(x, xs)), ...);
 * }
 *
 * std::gcd(int a, int b)
 *
 * cout << setprecision(n);
 *
 * set with custom ordering
 * set<ll, decltype(&cmp)> qu(cmp);
 *
 */

typedef int64_t ll;

void solve() {

    ll n, h;
    cin >> n >> h;

    //cerr << "\nn=" << n << "; h=" << h;

    vector<pair<pair<ll,ll>,ll>> v(n, {{0,0}, 0});
    // {end, start}
    for(ll i = 0; i < n; i++) {
        cin >> v[i].first.second >> v[i].first.first;
        v[i].second = i + 1;
    }

    // ket darab greedy menet  
    // szortirozzuk a vegeik szerint

    //cerr << "\nv=" << v;

    sort(v.begin(), v.end());
    ll currm = 0;
    ll currt = 0;

    vector<ll> ms;
    vector<ll> tn;
    //cerr << "\ncurr=" << curr;
    for(ll i = 0; i < n; i++) {
        ll hstart = v[i].first.second;
        ll hend = v[i].first.first;
        //cerr << "\ni=" << i << "; v[i]=" << v[i];
        //cerr << "\ncurrm=" << currm << "; currt=" << currt;
        //cerr << "\nhend=" << hend;
        if(currm <= currt) {
            // elobb a curr-t nezzuk meg
            if(currt <= hstart) {
                currt = hend + 1;
                tn.push_back(v[i].second);
            }else if(currm <= hstart) {
                currm = hend + 1;
                ms.push_back(v[i].second);
            }
        }else{
            if(currm <= hstart) {
                currm = hend + 1;
                ms.push_back(v[i].second);
            }else if(currt <= hstart) {
                currt = hend + 1;
                tn.push_back(v[i].second);
            }
        }
    }

    cout << ms.size() << " " << tn.size() << "\n";
    for(const auto & x : ms) {
        cout << x << " ";
    }
    cout << "\n";
    for(const auto & x : tn) {
        cout << x << " ";
    }

}

int main()
{
    std::ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr);

    solve();

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/04ms564 KiB
3Elfogadva1/11ms316 KiB
4Elfogadva1/11ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms384 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva3/31ms316 KiB
10Elfogadva1/11ms316 KiB
11Elfogadva1/11ms316 KiB
12Elfogadva2/21ms316 KiB
13Elfogadva2/21ms316 KiB
14Elfogadva2/21ms316 KiB
15Elfogadva2/21ms316 KiB
16Elfogadva3/32ms316 KiB
17Elfogadva2/239ms2784 KiB
18Elfogadva2/237ms2776 KiB
19Elfogadva4/439ms2780 KiB
20Elfogadva4/439ms2780 KiB
21Elfogadva4/439ms2960 KiB
22Elfogadva4/439ms3124 KiB
23Elfogadva4/446ms3756 KiB