0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:56:26 +00:00

#1058. 【APIO/CTSC 2007】数据备份

https://sjzezoj.com/submission/64193
This commit is contained in:
Baoshuo Ren 2022-11-12 15:59:06 +08:00
parent e6d3d9d61a
commit 20be6494c0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
42 changed files with 195 additions and 0 deletions

72
S2OJ/1058/1058.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
#include <limits>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 100005;
int n, k, a[N], pre[N], suf[N];
long long c[N], ans;
std::priority_queue<
std::pair<int, long long>,
std::vector<std::pair<int, long long>>,
auto(*)(std::pair<int, long long>, std::pair<int, long long>)->bool>
q([](std::pair<int, long long> a, std::pair<int, long long> b) -> bool {
return a.second > b.second;
});
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
c[i] = static_cast<long long>(a[i + 1]) - a[i];
pre[i] = i - 1;
suf[i] = i + 1;
}
suf[n - 1] = 0;
for (int i = 1; i < n; i++) {
q.emplace(i, c[i]);
}
while (k--) {
auto o = q.top();
q.pop();
if (o.second != c[o.first]) {
k++;
continue;
}
ans += o.second;
int l = pre[o.first],
r = suf[o.first];
suf[o.first] = suf[r];
pre[suf[o.first]] = o.first;
pre[o.first] = pre[l];
suf[pre[o.first]] = o.first;
c[o.first] = (l && r) ? std::min(static_cast<long long>(std::numeric_limits<int>::max()), c[l] + c[r] - c[o.first]) : std::numeric_limits<int>::max();
c[l] = c[r] = std::numeric_limits<int>::max();
q.emplace(o.first, c[o.first]);
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1058/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/data9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1058/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.