83402024-01-14 19:23:10anonTanúk (45 pont)cpp17Elfogadva 45/45120ms20224 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
int main() {
    FastIO;
    bool flag;
    ll i, j, mh, N, H, K;
    cin >> N >> H >> K;
    vector<ll> tss(K);
    vector<array<ll, 2>> guests(N);
    for(i = 0; i < K; i++)
        cin >> tss[i];
    for(i = 0; i < N; i++)
        cin >> guests[i][0] >> guests[i][1];
    sort(all(tss));
    vector<array<vector<ll>, 2>> eps(H + 1);
    for(i = 0; i < N; i++) {
        for(j = 0; j < 2; j++)
            eps[guests[i][j]][j].push_back(i);
    }
    unordered_set<ll> here;
    vector<bool> bad_guests(N, false);
    if(N <= 80000) {
        fill(all(bad_guests), true);
        j = 0;
        for(i = 1; i <= H && j < K; i++) {
            for(const auto &x : eps[i][0])
                here.insert(x);
            if(i == tss[j]) {
                for(const auto &x : here)
                    bad_guests[x] = false;
                j++;
            }
            for(const auto &x : eps[i][1])
                here.erase(x);
        }
        here.clear();
    }
    unordered_set<ll> lc;
    vector<ll> ans;
    j = 0;
    for(i = 1; i <= H; i++) {
        for(const auto &x : eps[i][0]) {
            if(!bad_guests[x])
                here.insert(x);
        }
        if(j < K && i == tss[j]) {
            if(ans.empty())
                lc = here;
            else {
                for(const auto &x : here) {
                    if(guests[ans.back()][1] < guests[x][0])
                        lc.insert(x);
                }
            }
            j++;
        }
        flag = !lc.empty();
        if(flag) {
            flag = false;
            for(const auto &x : eps[i][1]) {
                if(lc.find(x) != lc.end()) {
                    flag = true;
                    break;
                }
            }
        }
        if(flag) {
            mh = *(here.begin());
            for(const auto &x : here) {
                if(guests[mh][1] < guests[x][1])
                    mh = x;
            }
            ans.push_back(mh);
            j = upper_bound(all(tss), guests[mh][1]) - tss.begin();
            lc.clear();
        }
        for(const auto &x : eps[i][1]) {
            if(!bad_guests[x])
                here.erase(x);
        }
    }
    cout << ans.size() << '\n';
    for(const auto &x : ans)
        cout << x + 1 << ' ';
    cout << '\n';
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base45/45
1Elfogadva0/03ms1824 KiB
2Elfogadva0/043ms12484 KiB
3Elfogadva2/232ms12444 KiB
4Elfogadva2/23ms3040 KiB
5Elfogadva2/23ms2608 KiB
6Elfogadva2/24ms3260 KiB
7Elfogadva2/24ms3356 KiB
8Elfogadva2/24ms3304 KiB
9Elfogadva2/26ms7196 KiB
10Elfogadva2/24ms4680 KiB
11Elfogadva2/27ms7768 KiB
12Elfogadva2/28ms8168 KiB
13Elfogadva2/29ms8252 KiB
14Elfogadva2/28ms5848 KiB
15Elfogadva2/213ms6364 KiB
16Elfogadva2/213ms9728 KiB
17Elfogadva2/254ms14632 KiB
18Elfogadva2/271ms17836 KiB
19Elfogadva2/274ms15408 KiB
20Elfogadva2/282ms15740 KiB
21Elfogadva2/272ms19040 KiB
22Elfogadva2/286ms19428 KiB
23Elfogadva2/272ms19532 KiB
24Elfogadva3/3120ms20224 KiB