QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788281#9730. Elevator IIshinonomezhouWA 213ms3792kbC++142.7kb2024-11-27 16:24:562024-11-27 16:26:11

Judging History

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

  • [2024-11-27 16:26:11]
  • 评测
  • 测评结果:WA
  • 用时:213ms
  • 内存:3792kb
  • [2024-11-27 16:24:56]
  • 提交

answer

#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
#include <utility>
#include <vector>

// #define x first
// #define y second

using namespace std;

typedef double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

const int maxn = 2e6 + 50;
const ll inf = 0x3f3f3f3f3f3f;
const vector<pll> dxy = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

ll n, f;

void solve() {
  cin >> n >> f;
  vector<pll> v;
  map<pll, vector<ll>> mp;
  for (ll i = 1; i <= n; i++) {
    ll l, r;
    cin >> l >> r;
    v.push_back({l, r});
    mp[{l, r}].push_back(i);
  }

  sort(v.begin(), v.end());

  vector<vector<ll>> q;
  multiset<pll, greater<>> st;

  for (ll i = 0; i < (ll)v.size(); i++) {
    auto [l, r] = v[i];
    if (q.empty()) {
      vector<ll> w;
      w.push_back(i);
      q.push_back(w);
      st.insert({r, q.size() - 1});
    } else {
      // 第一个大于等于
      auto d = lower_bound(
          st.begin(), st.end(), make_pair(l, 0), [&](pll p1, pll p2) {
            return tie(p1.first, p1.second) > tie(p2.first, p2.second);
          });
      if (d != st.end()) {
        st.erase(d);
        ll p = d->second;
        q[p].push_back(i);
        st.insert({r, p});
      } else {
        vector<ll> w;
        w.push_back(i);
        q.push_back(w);
        st.insert({r, q.size() - 1});
      }
    }
  }

  vector<ll> ans;

  bool flag = false;
  for (ll qi = 0; qi < (ll)q.size(); qi++) {
    auto vi = q[qi];
    for (ll i = 0; i < (ll)vi.size(); i++) {
      ll p = vi[i];
      if (v[p].first >= f &&
          (i == 0 || (i - 1 >= 0 && v[vi[i - 1]].second <= f))) {
        for (ll j = i; j < (ll)vi.size(); j++) {
          ans.push_back(vi[j]);
        }
        for (ll j = 0; j < i; j++) {
          ans.push_back(vi[j]);
        }
        flag = true;
        q.erase(q.begin() + qi);
        break;
      }
    }
    if (flag)
      break;
  }

  for (auto i : q) {
    for (auto j : i) {
      ans.push_back(j);
    }
  }

  ll tot = 0ll;
  for (ll i = 0; i < (ll)ans.size(); i++) {
    ll p = ans[i];
    if (i == 0) {
      tot = max(v[p].first - f, 0ll) + v[p].second - v[p].first;
    } else {
      tot += max(v[p].first - v[ans[i - 1]].second, 0ll) + v[p].second -
             v[p].first;
    }
  }
  cout << tot << '\n';
  for (auto i : ans) {
    cout << mp[v[i]].front() << ' ';
    mp[v[i]].erase(mp[v[i]].begin());
  }
  cout << '\n';
}

void init() {
  // init_primes();
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int _t = 1;
  cin >> _t;
  cin.get();
  while (_t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

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

output:

11
3 2 1 4 
5
2 1 

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 213ms
memory: 3792kb

input:

6100
19 52
51 98
2 83
40 58
96 99
39 55
72 94
15 17
4 15
48 99
2 99
77 78
35 77
44 62
79 81
30 31
1 48
48 76
68 99
60 66
6 19
44 53
64 92
17 28
67 98
9 99
40 65
16 27
99 100
15 56
4 6
24 97
84 96
47 49
37 38
77 79
13 40
13 92
71 100
47 93
90 91
72 81
15 48
32 71
19 17
95 99
10 23
18 100
90 93
52 92
...

output:

583
16 17 11 14 2 10 8 5 7 15 12 3 19 18 13 6 4 9 1 
244
1 2 5 3 6 4 
485
16 14 5 3 9 6 8 13 10 15 2 11 4 1 7 12 
772
18 2 14 9 15 8 7 4 1 11 17 3 6 13 19 16 10 12 5 
289
10 12 7 15 1 13 3 9 11 14 5 8 6 4 2 
468
3 15 2 17 12 18 19 6 1 14 16 20 9 5 7 11 8 13 4 10 
123
2 3 4 1 
232
3 7 10 9 6 1 4 5 2 ...

result:

wrong answer Participant's cost is 583, which is worse than jury's cost 524 (test case 1)