19042022-12-08 17:53:51sztomiMúzeumi őrökcpp17Accepted 40/40185ms48508 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll inf = 1e16;

int n, e, u;
vector<int> ar;
vector<int> kezd;
vector<int> veg;
vector<int> ind;
vector<pair<ll, vector<int>>> fa;
vector<int> legmesszebb;

int bal(int x){
    return 2*x;
}

int jobb(int x){
    return 2*x+1;
}

int szulo(int x){
    return x / 2;
}

struct comp{
    bool operator()(int a, int b){
        if(kezd[a] < kezd[b]) return true;
        if(kezd[a] > kezd[b]) return false;
        return veg[a] > veg[b];
    }
};


void allit(pair<ll, vector<int>> ertek, int ind){
    if(ind == 0) return;

    if(fa[ind].first > ertek.first){
        fa[ind] = ertek;
        allit(ertek, szulo(ind));
    }
}

pair<ll, vector<int>> legjobb(int keres_e, int keres_u, int elso, int utolso, int ind){
    if(ind >= fa.size()) return {inf, vector<int>()};
    if(keres_u < elso) return {inf, vector<int>()};
    if(keres_e > utolso) return {inf, vector<int>()};
    if(elso > utolso) return {inf, vector<int>()};

    if(elso == utolso) return fa[ind];
    if(keres_e <= elso && utolso <= keres_u) return fa[ind];

    pair<ll, vector<int>> id1, id2;
    id1 = legjobb(keres_e, keres_u, elso, (elso + utolso) / 2, bal(ind));
    id2 = legjobb(keres_e, keres_u, (elso + utolso) / 2 + 1, utolso, jobb(ind));
    if(id1.first < id2.first){
        return id1;
    }
    else{
        return id2;
    }
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> e >> u;
    u -= e-1;
    ar.assign(n+1, 0);
    kezd.assign(n+1, 0);
    veg.assign(n+1, 0);
    ind.assign(n+1, 0);

    for(int i = 1; i <= n; i++){
        ind[i] = i;
        cin >> kezd[i] >> veg[i] >> ar[i];
        kezd[i] -= e-1;
        veg[i] -= e-1;
    }
    sort(ind.begin(), ind.end(), comp());

    /*
    cout << "-------------\n";
    for(int x : ind){
        cout << kezd[x] << " " << veg[x] << " " << ar[x] << "\n";
    }
    cout << "---\n";
    */

    // minden allashoz a legmessszebb elerot beallitani
    legmesszebb.assign(n+1, -1);
    for(int i = 0; i <= n; i++){
        int l, r, m;
        l = i;
        r = n;
        while(l <= r){
            m = (l+r) / 2;
            if(veg[ind[i]] + 1 >= kezd[ind[m]]){
                l = m + 1;
                legmesszebb[i] = m;
            }
            else{
                r = m-1;
            }
        }
    }

    // szegmensfa inicializalas
    int fa_meret = 131072;
    fa.assign(2*fa_meret+1, {inf, vector<int>()});

    pair<ll, vector<int>> ret, ideigl;
    for(int utolso = n; utolso >= 0; utolso--){
        if(veg[ind[utolso]] == u){
            ret = {ar[ind[utolso]], vector<int>()};
            ret.second.push_back(ind[utolso]);
        }
        else{
            ret = legjobb(utolso+1, legmesszebb[utolso], 0, fa_meret-1, 1);
            if(ret.first != inf){
                ret.first += ar[ind[utolso]];
                ret.second.push_back(ind[utolso]);
            }
        }
        allit(ret, utolso + fa_meret);
/*
        for(int i = fa_meret; i <= fa_meret + n; i++){
            cout << fa[i].first << " ";
        }
        cout << "\n";
*/
    }
    ret = fa[fa_meret];


    if(ret.first == inf){
        cout << "-1\n";
    }
    else{
        cout << ret.first << "\n";
        cout << ret.second.size()-1 << " ";
        for(int i = ret.second.size()-2; i >= 0; i--){
            cout << ret.second[i] << " ";
        }
        cout << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/08ms17976 KiB
2Accepted0/039ms47660 KiB
3Accepted1/18ms18612 KiB
4Accepted3/38ms18688 KiB
5Accepted2/28ms18584 KiB
6Accepted2/28ms18588 KiB
7Accepted2/28ms18844 KiB
8Accepted2/28ms19044 KiB
9Accepted2/28ms19248 KiB
10Accepted2/2175ms47252 KiB
11Accepted2/2184ms47532 KiB
12Accepted2/29ms19456 KiB
13Accepted2/214ms21480 KiB
14Accepted3/332ms38636 KiB
15Accepted3/337ms41500 KiB
16Accepted2/2185ms48296 KiB
17Accepted2/2184ms48508 KiB
18Accepted2/28ms20116 KiB
19Accepted2/29ms20116 KiB
20Accepted2/28ms20372 KiB
21Accepted2/28ms20572 KiB