QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56442 | #2556. Yet Another Interval Graph Problem | mendicillin2# | WA | 3ms | 3720kb | C++17 | 1.4kb | 2022-10-19 16:21:28 | 2022-10-19 16:21:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<tuple<int, int, ll>> stuff(N);
ll total = 0;
for (auto& [r, l, w] : stuff) {
cin >> l >> r >> w;
total += w;
}
sort(stuff.begin(), stuff.end());
const int S = 1 << (N <= 1 ? 0 : 32 - __builtin_clz(N-1));
vector<vector<ll>> seg(K+1, vector<ll>(2*S));
auto query = [&](int k, int l, int r) -> ll {
ll res = 0;
for (int a = S+l, b = S+r; a < b; a /= 2, b /= 2) {
if (a & 1) {
res = max(res, seg[k][a++]);
}
if (b & 1) {
res = max(res, seg[k][--b]);
}
}
return res;
};
auto upd = [&](int k, int i, ll val) -> void {
seg[k][S+i] = max(seg[k][S+i], val);
for (int a = (S+i)/2; a >= 1; a /= 2) {
seg[k][a] = max(seg[k][2*a], seg[k][2*a+1]);
}
};
for (int i = 0; i < N; i++) {
auto [r, l, w] = stuff[i];
int j = 0;
ll best_1 = 0;
while (j < i) {
int r2, l2, w2;
tie(r2, l2, w2) = stuff[j];
if (r2 < l) {
ll val = query(K, j, j+1) + w;
best_1 = max(best_1, val);
} else {
break;
}
j++;
}
ll pbest = best_1;
for (int k = 1; k <= K; k++) {
ll val = query(k-1, j, i) + w;
pbest = max(pbest, val);
upd(k, i, pbest);
}
}
ll max_left = query(K, 0, N);
ll ans = total - max_left;
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3720kb
input:
5 2 1 4 1 3 6 2 5 8 5 7 10 2 9 12 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3564kb
input:
5 1 2 6 5 4 6 2 8 8 5 1 3 4 6 8 7
output:
12
result:
ok single line: '12'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
1 1 260947663 693934985 986106006
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
2 2 148610427 148610427 611594176 148610427 148610427 241979785
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
2 2 189944467 208945642 113891402 208945642 235053342 250664551
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3680kb
input:
2 2 259102823 862504466 73871288 91533165 259102823 447104717
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3716kb
input:
2 2 634621570 811155007 87507743 299710238 563644023 98163867
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
13 5 385168347 385168347 99054846 385168347 385168347 350748474 385168347 385168347 354902398 385168347 385168347 585042031 385168347 385168347 292548257 385168347 385168347 440215041 385168347 385168347 672336022 385168347 385168347 47484008 385168347 385168347 169165503 385168347 385168347 7956210...
output:
1929854426
result:
ok single line: '1929854426'
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 3508kb
input:
13 6 249108165 750799499 699592153 249108165 457151813 987869795 134537888 782870665 390805464 134537888 782870665 649518079 204359052 634307327 182450369 204359052 774773106 730624930 249108165 774773106 537210767 204359052 774773106 97138905 204359052 457151813 416638849 134537888 524514128 250590...
output:
1060999566
result:
wrong answer 1st lines differ - expected: '1237015857', found: '1060999566'