QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#853115 | #9730. Elevator II | ucup-team5234# | AC ✓ | 798ms | 29372kb | C++23 | 2.1kb | 2025-01-11 15:48:48 | 2025-01-11 15:48:49 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
const ll INF = (1LL << 60);
template <class T> struct BIT {
int n;
vector<T> a;
BIT(int m) : n(m), a(m + 1, 0) {}
void add(int x, T y) {
x ++;
while(x <= n) {
a[x] += y;
x += x & -x;
}
}
T sum(int x) {
T r = 0;
while(x > 0) {
r += a[x];
x -= x & -x;
}
return r;
}
T sum(int x, int y) {
return sum(y) - sum(x);
}
};
void solve() {
ll n, f;
cin >> n >> f;
map<ll, ll> mp;
int sz = 0;
vector<ll> inv;
vector<ll> le(n), ri(n);
rep(i, n) {
cin >> le[i] >> ri[i];
mp[le[i]] ++;
mp[ri[i]] ++;
}
mp[f] ++;
for(auto [x, y] : mp) {
inv.pb(x);
mp[x] = sz ++;
}
BIT<ll> bit(sz);
rep(i, n) {
bit.add(mp[le[i]], 1);
bit.add(mp[ri[i]], -1);
}
set<pair<ll, int>> st;
rep(i, n) {
st.insert({le[i], i});
}
ll ans = 0;
int inf = 1 << 30;
vector<ll> vec;
while(!st.empty()) {
if(!bit.sum(0, mp[f])) {
auto itr = st.lower_bound({f, -inf});
if(itr != st.end()) {
auto [x, y] = *itr;
ans += x - f;
bit.add(mp[x], -1);
bit.add(mp[ri[y]], 1);
st.erase(itr);
f = ri[y];
ans += ri[y] - le[y];
vec.pb(y + 1);
continue;
}
}
auto itr = st.upper_bound({f, inf});
itr --;
auto [x, y] = *itr;
bit.add(mp[x], -1);
bit.add(mp[ri[y]], 1);
st.erase(itr);
f = ri[y];
ans += ri[y] - le[y];
vec.pb(y + 1);
}
cout << ans << endl;
for(ll e : vec) cout << e << " ";
cout << endl;
}
int main() {
int t;
cin >> t;
rep(i, t) solve();
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
11 3 4 1 2 5 2 1
result:
ok ok 2 cases (2 test cases)
Test #2:
score: 0
Accepted
time: 259ms
memory: 3924kb
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 1 4 14 11 6 18 19 17 9 13 3 5 12 15 7 8 10 2 16 194 3 5 4 2 1 6 397 4 13 5 8 14 11 1 12 6 7 16 15 2 10 9 3 733 18 16 4 17 8 1 5 12 10 19 13 14 6 11 3 7 15 9 2 244 1 15 3 2 8 12 4 6 14 5 10 11 9 13 7 422 18 11 10 6 7 2 13 20 4 8 5 15 9 16 14 1 19 3 12 17 104 1 4 3 2 187 5 6 4 8 2 3 1 9 10 ...
result:
ok ok 6100 cases (6100 test cases)
Test #3:
score: 0
Accepted
time: 798ms
memory: 29372kb
input:
3 100000 9859 150464 951410 637107 897197 236268 936879 353406 403927 511229 999416 861211 958428 186246 446149 162388 805753 449016 817386 147119 604340 579101 926848 958992 987299 859662 907007 507058 690951 719158 856587 789149 927957 691705 707085 694110 845505 192759 616586 905489 935507 937041...
output:
24903933702 79516 24281 16079 72303 93097 35444 6315 85282 72245 76099 7904 12929 72396 65474 13509 51617 64518 17116 1391 69859 94976 86643 52272 9868 78418 75539 36677 50759 70692 43527 59278 99948 47680 41692 64055 27729 7685 22139 91293 15697 79107 25422 55091 23408 95233 84324 21636 79982 89542...
result:
ok ok 3 cases (3 test cases)
Test #4:
score: 0
Accepted
time: 576ms
memory: 26932kb
input:
3 100000 932101 80818 80823 538842 538844 406812 406818 625053 625054 511066 511073 667363 667365 527022 527023 621329 621331 855832 855852 796168 796169 268927 268929 650891 650895 312793 312794 873256 873260 424896 424929 266271 266272 902201 902209 842863 842864 361599 361610 647851 647855 148132...
output:
986597 19954 75334 23297 69750 59484 82641 47710 70352 30352 11990 73429 69618 61591 58790 47387 41138 23379 20783 19378 19101 41160 44088 30498 74602 34312 43082 24376 10872 13641 11660 99646 20276 70364 12832 20274 15412 42804 6654 60667 72528 68730 31129 83583 94175 74178 72990 77157 82305 60601 ...
result:
ok ok 3 cases (3 test cases)
Test #5:
score: 0
Accepted
time: 670ms
memory: 29264kb
input:
3 100000 375117879 637628712 637644704 788784579 788792294 804734775 804734822 332639566 332642798 143113598 143114045 132119073 132122341 684483097 684513821 484676670 484678332 661667340 661668818 777865379 777870254 142495696 142495995 101735856 101740588 906481102 906481965 360087766 360091064 1...
output:
872643717 43549 34676 31878 49124 12077 8140 13605 76831 10834 96613 83688 46028 65944 14511 56152 84791 1759 60404 73244 38124 93732 74294 8688 64153 56500 39213 27938 93350 21680 36926 8295 8832 69685 1025 22233 14796 83881 83105 72820 95432 90168 29163 20496 4937 51441 96515 46657 82775 90528 380...
result:
ok ok 3 cases (3 test cases)
Extra Test:
score: 0
Extra Test Passed