QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#736314 | #7950. Lucky Draws | duckindog | WA | 519ms | 1231352kb | C++23 | 1.9kb | 2024-11-12 09:48:08 | 2024-11-12 09:48:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 20'000 + 10,
K = 500 + 10;
int n, k;
pair<int, int> p[N];
vector<int> allValue;
int pref[N][N], d[N];
inline int cal(int l, int r) {
return pref[r][r] - pref[l - 1][r] - pref[r][l - 1] + pref[l - 1][l - 1];
}
int f[K][N];
void dnc(int l, int r, int lt, int rt, int stage) {
if (l > r) return;
int mid = (l + r) >> 1;
auto& ret = f[stage][mid];
int opt = lt;
for (int i = lt; i <= min(mid, rt); ++i) {
int value = f[stage - 1][i - 1] + cal(i, mid);
if (value > ret) ret = value, opt = i;
}
dnc(l, mid - 1, lt, opt, stage);
dnc(mid + 1, r, opt, rt, stage);
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> p[i].first >> p[i].second;
for (int i = 1; i <= n; ++i) {
allValue.push_back(p[i].first);
allValue.push_back(p[i].second);
}
sort(allValue.begin(), allValue.end());
allValue.erase(unique(allValue.begin(), allValue.end()), allValue.end());
for (int i = 1; i <= n; ++i) {
p[i].first = upper_bound(allValue.begin(), allValue.end(), p[i].first) - allValue.begin();
p[i].second = upper_bound(allValue.begin(), allValue.end(), p[i].second) - allValue.begin();
pref[p[i].first][p[i].second] += 1;
d[p[i].first] += 1; d[p[i].second + 1] -= 1;
}
for (int i = 1; i <= (int)allValue.size(); ++i) {
for (int j = 1; j <= (int)allValue.size(); ++j)
pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
}
for (int i = 1; i <= (int)allValue.size(); ++i) {
d[i] += d[i - 1];
f[1][i] = d[i];
}
for (int i = 2; i <= k; ++i) dnc(1, allValue.size(), 1, allValue.size(), i);
int answer = 0;
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= (int)allValue.size(); ++j) answer = max(answer , f[i][j]);
}
cout << answer << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5740kb
input:
5 2 1 2 1 4 3 6 4 7 5 6
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5660kb
input:
3 2 2 4 1 3 3 5
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5720kb
input:
4 1 2 3 1 1 4 5 4 5
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
7 2 5 6 7 9 7 7 1 4 2 3 4 7 4 7
output:
6
result:
ok single line: '6'
Test #5:
score: -100
Wrong Answer
time: 519ms
memory: 1231352kb
input:
10000 50 -16187 -16186 743439 743441 -995450 -995449 921242 921242 -287646 -287644 110263 110264 650110 650110 897150 897151 262837 262839 935191 935193 6079 6080 815160 815162 -624776 -624774 -782088 -782086 486051 486052 -704289 -704287 -592330 -592329 -943804 -943803 43046 43047 -896912 -896910 -...
output:
10000
result:
wrong answer 1st lines differ - expected: '100', found: '10000'