QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#746288 | #9730. Elevator II | shenchuan_fan | WA | 101ms | 3744kb | C++20 | 1.8kb | 2024-11-14 14:08:02 | 2024-11-14 14:08:04 |
Judging History
answer
/**/
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 1e7 + 10, M = 5010, mod = 998244353;
const int inf = 1e9;
struct node{
int x, y, id;
};
void solve() {
int n, f;
cin >> n >> f;
vector <node> a(n + 1);
int ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i].x >> a[i].y;
a[i].id = i;
ans += a[i].y - a[i].x;
}
set <int> unuse;
for(int i = 1; i <= n; i++) unuse.insert(i);
sort(a.begin() + 1, a.end(), [&](node a, node b){
return a.x < b.x;
});
int mx = f;
vector <int> nxt(n + 1);
vector <node> unf;
map <int,vector<int>> mp;
mp[f].push_back(0);
for(int i = 1; i <= n; i++){
auto [l, r, idx] = a[i];
if(l > mx){
ans += l - mx;
nxt[mp[mx].back()] = idx;
if(mp[mx].back() != 0) unuse.erase(mp[mx].back());
mp[mx].pop_back();
}else if(r > mx){
nxt[mp[mx].back()] = idx;
unuse.erase(mp[mx].back());
mp[mx].pop_back();
}
mx = max(mx, r);
mp[r].push_back(idx);
}
for(auto u: unuse) unf.push_back(a[u]);
sort(unf.begin(), unf.end(), [&](node a, node b){
return a.y > b.y;
});
if(nxt[mp[mx].back()] == 0) nxt[mp[mx].back()] = unf[0].id;
for(int i = 0; i + 1 < unf.size(); i++){
//cout << unf[i].id << " ";
nxt[unf[i].id] = unf[i + 1].id;
unuse.erase(unf[i].id);
}
//cout << unf[unf.size() - 1].id << "\n";
/*for(int i = 0; i <= n; i++){
cout << nxt[i] << " \n"[ i == n ];
}*/
cout << ans << "\n";
int p = 0;
for(int i = 0; i < n; i++){
if(nxt[p] != 0){
cout << nxt[p] << " ";
p = nxt[p];
}
}
cout << "\n";
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T = 1;
cin >> T;
while(T--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
11 2 3 1 4 5 2 1
result:
ok ok 2 cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 101ms
memory: 3744kb
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:
524 2 10 1 6 14 11 12 17 19 13 3 5 16 15 7 8 194 5 4 2 6 1 3 397 9 7 3 733 2 15 7 12 18 14 9 19 2 15 7 12 18 14 9 19 2 15 7 244 3 11 9 13 7 422 17 18 1 6 11 2 10 13 9 4 12 20 14 5 15 19 8 16 3 17 104 3 2 187 4 1 2 6 5 10 117 2 4 5 2 4 5 92 1 2 36 1 2 364 16 8 17 18 3 125 366 2 8 4 3 10 ...
result:
wrong answer Integer parameter [name=a_i] equals to 194, violates the range [1, 19] (test case 1)