QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#562026 | #3563. Treatment Project | seungni | 4 | 76ms | 15292kb | C++17 | 5.3kb | 2024-09-13 14:22:38 | 2024-09-13 14:22:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
ll N, M, sz;
pair<ll, pair<pii, ll>> arr[100005];
vector<pii> graph[100005];
ll seg[200505 * 2];
void update(int pos, ll v) {
pos += sz;
seg[pos] = min(seg[pos], v);
for (; pos > 0; pos >>= 1) seg[pos >> 1] = min(seg[pos], seg[pos ^ 1]);
return;
}
ll query(int l, int r) {
r++;
ll ret = inf;
for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
if (l & 1) ret = min(ret, seg[l++]);
if (r & 1) ret = min(ret, seg[--r]);
}
return ret;
}
void Dijkstra(int S, vector<ll> &dist) {
priority_queue<pii, vector<pii>, greater<>> pq;
dist[S] = 0;
pq.push({0, S});
while (pq.size()) {
pii t = pq.top();
pq.pop();
ll now = t.second, v = t.first;
if (dist[now] < v) continue;
for (auto &[next, cost]: graph[now]) {
ll ncost = v + cost;
if (dist[next] > ncost) {
dist[next] = ncost;
pq.push({ncost, next});
}
}
}
}
void subtask_1() {
vector<ll> v;
v.push_back(0);
v.push_back(1), v.push_back(N);
for (int i = 0; i < M; i++) {
v.push_back(arr[i].second.first.first);
v.push_back(arr[i].second.first.second);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
sz = v.size();
sort(arr, arr + M, [&](pair<ll, pair<pii, ll>> a, pair<ll, pair<pii, ll>> b) {
return a.second.first.second < b.second.first.second;
});
for (int i = 0; i < M; i++) {
ll L = arr[i].second.first.first, R = arr[i].second.first.second;
L = lower_bound(v.begin(), v.end(), L) - v.begin();
R = lower_bound(v.begin(), v.end(), R) - v.begin();
arr[i].second.first = {L, R};
}
vector<ll> dp(sz + 5, inf);
memset(seg, 0x3f, sizeof(seg));
dp[0] = 0;
update(0, dp[0]);
for (int i = 0; i < M; i++) {
ll l = arr[i].second.first.first, r = arr[i].second.first.second, c = arr[i].second.second;
ll idx = lower_bound(v.begin(), v.end(), v[l] - 1) - v.begin();
dp[r] = min(dp[r], query(idx, r) + c);
update(r, dp[r]);
}
int idx = lower_bound(v.begin(), v.end(), N) - v.begin();
if (dp[idx] == inf) cout << -1;
else cout << dp[idx];
return;
}
void subtask_2() {
ll ans = inf;
sort(arr, arr + M);
for (int i = 0; i < (1 << M); i++) {
vector<int> v;
ll cost = 0;
for (int j = 0; j < M; j++) {
if (i & (1 << j)) v.push_back(j), cost += arr[j].second.second;
}
vector<pair<pii, ll>> now;
now.push_back({{1, N}, 0});
for (int j: v) {
vector<pair<pii, ll>> nxt;
ll T = arr[j].first, L = arr[j].second.first.first, R = arr[j].second.first.second;
for (auto &[range, t]: now) {
ll l = range.first, r = range.second;
l -= T - t, l = max(l, 1LL);
r += T - t, r = min(r, N);
if (l < L) nxt.push_back({{l, min(r, L - 1)}, T});
if (r > R) nxt.push_back({{max(l, R + 1), r}, T});
}
swap(nxt, now);
}
if (now.empty()) ans = min(ans, cost);
}
if (ans == inf) cout << -1;
else cout << ans;
return;
}
void subtask_3() {
int S = M, E = M + 1;
sort(arr, arr + M);
for (int i = 0; i < M; i++) {
ll t1 = arr[i].first, l1 = arr[i].second.first.first, r1 = arr[i].second.first.second, c1 = arr[i].second.second;
if (l1 == 1) {
graph[S].push_back({i, c1});
graph[i].push_back({S, 0});
}
if (r1 == N) {
graph[E].push_back({i, c1});
graph[i].push_back({E, 0});
}
for (int j = i + 1; j < M; j++) {
ll t2 = arr[j].first, l2 = arr[j].second.first.first, r2 = arr[j].second.first.second, c2 = arr[j].second.second;
ll diff = t2 - t1;
ll a = l1, b = r1;
if (a != 1) a += diff;
if (b != N) b -= diff;
if (a > b) continue;
b++;
a--;
if (a <= r2 && b >= l2) {
graph[i].push_back({j, c2});
graph[j].push_back({i, c1});
}
}
}
vector<ll> dist(M + 5, inf);
Dijkstra(S, dist);
if (dist[E] == inf) cout << -1;
else cout << dist[E];
return;
}
void solve() {
cin >> N >> M;
int sub_task1 = 1, sub_task2 = (M <= 16), sub_task3 = (M <= 5000);
for (int i = 0; i < M; i++) {
ll T, L, R, C;
cin >> T >> L >> R >> C;
if (T != 1) sub_task1 = 0;
arr[i] = {T, {{L, R}, C}};
}
if (sub_task1) {
subtask_1();
return;
}
if (sub_task2) {
//subtask_2();
//return;
}
if (sub_task3) {
subtask_3();
return;
}
return;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 60ms
memory: 15292kb
input:
1000000000 100000 1 811370001 811380000 1000000000 1 413190001 413200000 1000000000 1 462480001 462490000 1000000000 1 384860001 384870000 1000000000 1 543220001 543230000 1000000000 1 766300001 766310000 1000000000 1 348890001 348900000 1000000000 1 996350001 996360000 1000000000 1 302700001 302710...
output:
100000000000000
result:
ok single line: '100000000000000'
Test #2:
score: 4
Accepted
time: 49ms
memory: 15036kb
input:
1000000000 100000 1 949530001 949540000 1000000000 1 739970001 739980000 1000000000 1 199740001 199750000 1000000000 1 481170001 481180000 1000000000 1 691390001 691400000 1000000000 1 694040001 694050000 1000000000 1 229990001 230000000 1000000000 1 306470001 306480000 1000000000 1 293790001 293800...
output:
-1
result:
ok single line: '-1'
Test #3:
score: 4
Accepted
time: 51ms
memory: 13764kb
input:
1000000000 100000 1 999950001 999976550 1550 1 22208 50000 2793 1 18436 50000 6565 1 999999902 1000000000 99 1 1 1959 1959 1 999987171 1000000000 12830 1 13195 50000 11806 1 999950001 999987417 12417 1 999950001 999996988 21988 1 999950001 999994504 19504 1 999950001 999987988 12988 1 999950001 9999...
output:
49999
result:
ok single line: '49999'
Test #4:
score: 4
Accepted
time: 55ms
memory: 13544kb
input:
1000000000 100000 1 18068 50000 6933 1 999950001 999987700 12700 1 1 3107 3107 1 18416 50000 6585 1 999981021 1000000000 18980 1 999989599 1000000000 10402 1 999981949 1000000000 18052 1 1 23318 23318 1 999950001 999977889 2889 1 999989735 1000000000 10266 1 999950001 999977002 2002 1 999977230 1000...
output:
49998
result:
ok single line: '49998'
Test #5:
score: 4
Accepted
time: 32ms
memory: 13464kb
input:
1000000000 100000 1 1 10000000 145793232 1 10000001 20000000 480576404 1 20000001 30000000 579478535 1 30000001 40000000 972724773 1 40000001 50000000 195930803 1 50000001 60000000 42390962 1 60000001 70000000 280311272 1 70000001 80000000 265006415 1 80000001 90000000 646778234 1 90000001 100000000...
output:
103256696
result:
ok single line: '103256696'
Test #6:
score: 4
Accepted
time: 38ms
memory: 13344kb
input:
1000000000 100000 1 1 1000000 84881992 1 1000001 2000000 96486607 1 2000001 3000000 87474151 1 3000001 4000000 308931873 1 4000001 5000000 752155772 1 5000001 6000000 71781449 1 6000001 7000000 574465725 1 7000001 8000000 257711828 1 8000001 9000000 976891771 1 9000001 10000000 737457473 1 10000001 ...
output:
10202525555
result:
ok single line: '10202525555'
Test #7:
score: 4
Accepted
time: 34ms
memory: 13476kb
input:
1000000000 100000 1 1 100000 691341803 1 100001 200000 909165531 1 200001 300000 998253633 1 300001 400000 186389967 1 400001 500000 182412146 1 500001 600000 620222523 1 600001 700000 290853217 1 700001 800000 77492636 1 800001 900000 595119065 1 900001 1000000 632152167 1 1000001 1100000 751499859...
output:
911635058003
result:
ok single line: '911635058003'
Test #8:
score: 4
Accepted
time: 32ms
memory: 13464kb
input:
1000000000 100000 1 1 10000000 215217992 1 10000002 20000001 257813843 1 20000003 30000002 409648986 1 30000004 40000003 74292373 1 40000005 50000004 346679152 1 50000006 60000005 168032896 1 60000007 70000006 978832613 1 70000008 80000007 972209778 1 80000009 90000008 504905160 1 90000010 100000009...
output:
-1
result:
ok single line: '-1'
Test #9:
score: 4
Accepted
time: 31ms
memory: 13496kb
input:
1000000000 100000 1 1 1000000 339975845 1 1000002 2000001 924553880 1 2000003 3000002 221514681 1 3000004 4000003 814700766 1 4000005 5000004 606897055 1 5000006 6000005 542007635 1 6000007 7000006 833481194 1 7000008 8000007 36174314 1 8000009 9000008 677730964 1 9000010 10000009 328173604 1 100000...
output:
-1
result:
ok single line: '-1'
Test #10:
score: 4
Accepted
time: 38ms
memory: 13368kb
input:
1000000000 100000 1 1 100000 546836013 1 100002 200001 79898605 1 200003 300002 355510933 1 300004 400003 613504881 1 400005 500004 608643061 1 500006 600005 346108380 1 600007 700006 94237328 1 700008 800007 615885675 1 800009 900008 144998423 1 900010 1000009 452673262 1 1000011 1100010 602954095 ...
output:
-1
result:
ok single line: '-1'
Test #11:
score: 4
Accepted
time: 76ms
memory: 14484kb
input:
1000000000 100000 1 303811818 829165054 198988627 1 238315172 721819143 141698606 1 735738067 1000000000 894452247 1 361644024 743722594 115600786 1 833044862 1000000000 829396821 1 978649195 1000000000 121635824 1 656681592 1000000000 273711306 1 496003357 1000000000 145092871 1 545905300 100000000...
output:
685378438
result:
ok single line: '685378438'
Test #12:
score: 4
Accepted
time: 76ms
memory: 14684kb
input:
1000000000 100000 1 943316546 1000000000 216982980 1 19370137 444718109 622200963 1 244137695 646936606 337228786 1 721168313 1000000000 871779123 1 692826909 1000000000 475559515 1 172759072 444193083 393558194 1 902352909 1000000000 592749518 1 784704501 1000000000 46903352 1 476674919 820551472 7...
output:
8545005
result:
ok single line: '8545005'
Test #13:
score: 4
Accepted
time: 70ms
memory: 15036kb
input:
1000000000 100000 1 299540356 301014664 918798031 1 47063831 49122175 319472906 1 643593754 649240559 786327287 1 911355484 912220834 661864920 1 421773565 425654542 547070484 1 121293018 127328807 600494728 1 124896424 134073887 732623470 1 847918166 848422995 357034382 1 202634733 207639979 227135...
output:
640648629
result:
ok single line: '640648629'
Test #14:
score: 4
Accepted
time: 67ms
memory: 15024kb
input:
1000000000 100000 1 292785668 302238617 735249885 1 330242772 339770867 834706107 1 389294923 391540047 458089101 1 450680389 453059619 143967320 1 454972829 463399723 466799715 1 753057870 755431216 100716135 1 504170097 513605690 434206234 1 103062686 108678675 31594524 1 223332793 230476444 90289...
output:
566131778
result:
ok single line: '566131778'
Test #15:
score: 4
Accepted
time: 63ms
memory: 14956kb
input:
1000000000 100000 1 190249900 190686929 373454997 1 552611497 552775726 389849882 1 982934744 983745458 824523947 1 864133080 864437303 440840591 1 981480585 981574825 416048337 1 511607007 511657019 77913748 1 821534632 821810240 544332427 1 296802128 297062333 660771431 1 208063734 208493818 19912...
output:
60507750537
result:
ok single line: '60507750537'
Test #16:
score: 4
Accepted
time: 67ms
memory: 15020kb
input:
1000000000 100000 1 275121708 275841780 671595176 1 466556774 466575868 484670561 1 760216631 761110424 380331015 1 131452988 132345955 12662694 1 977640557 977642896 579869191 1 935760533 936394211 785322933 1 417528094 418262446 872043777 1 368926107 369906582 303043171 1 788412117 789358347 37981...
output:
60944102933
result:
ok single line: '60944102933'
Test #17:
score: 4
Accepted
time: 56ms
memory: 15024kb
input:
1000000000 100000 1 83134378 83939878 8 1 592189499 592792264 8 1 259250315 260076619 3 1 509562779 509615501 4 1 457433813 457988991 1 1 214916666 215313641 3 1 995959398 996917301 4 1 621550403 622406127 9 1 675067804 675700091 10 1 820894516 821281795 6 1 166308237 166609937 9 1 242380815 2431201...
output:
1663
result:
ok single line: '1663'
Test #18:
score: 4
Accepted
time: 74ms
memory: 14692kb
input:
1000000000 100000 1 943522993 1000000000 9 1 638122273 1000000000 5 1 285857010 626474643 4 1 356193761 483694746 3 1 257614831 796690153 1 1 575897497 1000000000 1 1 266218267 476247529 8 1 383225791 1000000000 2 1 561953671 1000000000 10 1 873960336 1000000000 9 1 33852012 588412399 3 1 496409891 ...
output:
4
result:
ok single line: '4'
Subtask #2:
score: 0
Wrong Answer
Test #19:
score: 5
Accepted
time: 2ms
memory: 7700kb
input:
1 1 1000000000 1 1 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #20:
score: 5
Accepted
time: 2ms
memory: 7668kb
input:
1000000000 16 6 2 2 1 4 999999997 999999999 4 2 999999997 1000000000 2 3 1 4 3 3 999999997 1000000000 3 5 999999998 999999999 3 6 999999999 999999999 1 2 1 4 2 6 3 999999998 1 999999987 1 1000000000 10 999999986 1 1000000000 10 999999985 1 1000000000 10 4 2 4 4 5 2 3 3 1 999999997 1000000000 1 1 1 4 1
output:
9
result:
ok single line: '9'
Test #21:
score: 5
Accepted
time: 0ms
memory: 7664kb
input:
1000000000 16 5 999999998 999999999 2 999999985 1 1000000000 8 5 2 3 3 2 1 4 2 4 2 4 3 6 3 999999998 1 1 999999997 1000000000 1 6 999999999 999999999 2 6 2 2 2 2 999999997 1000000000 2 3 999999997 1000000000 3 4 999999997 999999999 4 999999987 1 1000000000 10 1 1 4 1 999999986 1 1000000000 10 3 1 4 3
output:
8
result:
ok single line: '8'
Test #22:
score: 0
Wrong Answer
time: 2ms
memory: 7728kb
input:
1000000000 16 200000001 3 100000003 1000000000 1 1 100000001 1000000000 400000001 5 100000005 1000000000 1 900000000 1000000000 1000000000 500000001 899999995 999999995 1000000000 500000001 6 100000006 1000000000 600000001 899999994 999999994 1000000000 700000001 500000001 999999993 1000000000 40000...
output:
-1
result:
wrong answer 1st lines differ - expected: '16000000000', found: '-1'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%