QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786081#9730. Elevator IIqinsj#RE 0ms0kbC++203.5kb2024-11-26 20:12:012024-11-26 20:12:01

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 20:12:01]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 20:12:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>

#define db(args...) {\
    string _s = #args;replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ' ';
    err(++it, args...);
}

void solve() {
    int n, f;
    cin >> n >> f;

    #define a3 array<int, 3>
    vector<a3> a(n);
    vector<int> l(n), r(n);
    ll res = 0;
    vector<int> p = {f};
    int mxl = 0;
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
        mxl = max(mxl, l[i]);
        p.push_back(r[i]);
        res += r[i] - l[i];
        a[i] = {l[i], r[i], i};
    }
    sort(p.begin(), p.end()); p.erase(unique(p.begin(), p.end()), p.end());

    p.push_back(2e9);
    int m = p.size();
    vector<int> add[m];
    vector<int> del[m];
    for (auto [l, r, id] : a) {
        auto p1 = lower_bound(p.begin(), p.end(), l) - p.begin();
        auto p2 = lower_bound(p.begin(), p.end(), r + 1) - p.begin();
        add[p1].push_back(id);
        del[p2].push_back(id);
    }
    vector<int> jump(m, -1);
    multiset<pii> pq;
    for (int i = 0; i < m; i++) {
        for (auto id : add[i]) {
            pq.insert({r[id], id});
        }
        for (auto id : del[i]) {
            pq.extract({r[id], id});
        }
        if (pq.size()) {
            jump[i] = (*pq.rbegin()).second;
        }
    }

    // for (int i = 0; i < m; i++) {
    //     db(i, p[i], jump[i], r[jump[i]]);
    // } return;
    vector<int> visi(n);
    sort(a.begin(), a.end());

    vector<int> ans;
    while (f < mxl) {
        auto id = lower_bound(p.begin(), p.end(), f) - p.begin();
        // cerr << id << ' ' << m << '\n';
        if (id == m - 2) break;
        int nid = jump[id];
        if (visi[nid]) {
            auto costid = lower_bound(a.begin(), a.end(), a3{f + 1, 0, 0}) - a.begin();
            visi[a[costid][2]] = 1;
            ans.push_back(a[costid][2]);
            res += a[costid][0] - f;
            f = a[costid][0];
        } else {
            ans.push_back(nid);
            visi[nid] = 1;
            f = r[nid];
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (!visi[a[i][2]]) ans.push_back(a[i][2]);
    }

    cout << res << '\n';
    for (auto x : ans) {
        cout << x + 1 << " \n" [x == ans.back()];
    }

    // vector<int> visi(n + 1);
    // auto id = lower_bound(a.begin(), a.end(), a3{f + 1, 0, 0}) - a.begin();
    // if (id != 0) {
    //     int mxi = 0;
    //     for (int i = 0; i < id; i++) {
    //         if (a[i][1] > a[mxi][1]) {
    //             mxi = i;
    //         }
    //     }
    //     visi[mxi] = 1;
    //     ans.push_back(mxi);
    //     f = a[mxi][1];
    // }
    // for (int i = 0;)

    // int tmp = id;
    // while (id < n) {
    //     res += max(a[id][0] - f, 0);
    //     f = a[id][1];
    //     ans.push_back(a[id][2]);
    //     id++;
    // }
    // for (int i = tmp - 1; i >= 0; i--) ans.push_back(a[i][2]);
    // cout << res << '\n';
    // for (auto x : ans) {
    //     cout << x + 1 << " \n" [x == ans.back()];
    // }
}   
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
/*
g++ 1.cpp -std=c++20 -o 1 && ./1 < in.txt > out.txt
*/

詳細信息

Test #1:

score: 0
Runtime Error

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:


result: