From 20be6494c013254ca0998d2e3a0c52bc8a319892 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 12 Nov 2022 15:59:06 +0800 Subject: [PATCH] =?UTF-8?q?#1058.=20=E3=80=90APIO/CTSC=202007=E3=80=91?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/64193 --- S2OJ/1058/1058.cpp | 72 +++++++++++++++++++++++++++++++++++++ S2OJ/1058/data/data1.in | 3 ++ S2OJ/1058/data/data1.out | 3 ++ S2OJ/1058/data/data10.in | 3 ++ S2OJ/1058/data/data10.out | 3 ++ S2OJ/1058/data/data11.in | 3 ++ S2OJ/1058/data/data11.out | 3 ++ S2OJ/1058/data/data12.in | 3 ++ S2OJ/1058/data/data12.out | 3 ++ S2OJ/1058/data/data13.in | 3 ++ S2OJ/1058/data/data13.out | 3 ++ S2OJ/1058/data/data14.in | 3 ++ S2OJ/1058/data/data14.out | 3 ++ S2OJ/1058/data/data15.in | 3 ++ S2OJ/1058/data/data15.out | 3 ++ S2OJ/1058/data/data16.in | 3 ++ S2OJ/1058/data/data16.out | 3 ++ S2OJ/1058/data/data17.in | 3 ++ S2OJ/1058/data/data17.out | 3 ++ S2OJ/1058/data/data18.in | 3 ++ S2OJ/1058/data/data18.out | 3 ++ S2OJ/1058/data/data19.in | 3 ++ S2OJ/1058/data/data19.out | 3 ++ S2OJ/1058/data/data2.in | 3 ++ S2OJ/1058/data/data2.out | 3 ++ S2OJ/1058/data/data20.in | 3 ++ S2OJ/1058/data/data20.out | 3 ++ S2OJ/1058/data/data3.in | 3 ++ S2OJ/1058/data/data3.out | 3 ++ S2OJ/1058/data/data4.in | 3 ++ S2OJ/1058/data/data4.out | 3 ++ S2OJ/1058/data/data5.in | 3 ++ S2OJ/1058/data/data5.out | 3 ++ S2OJ/1058/data/data6.in | 3 ++ S2OJ/1058/data/data6.out | 3 ++ S2OJ/1058/data/data7.in | 3 ++ S2OJ/1058/data/data7.out | 3 ++ S2OJ/1058/data/data8.in | 3 ++ S2OJ/1058/data/data8.out | 3 ++ S2OJ/1058/data/data9.in | 3 ++ S2OJ/1058/data/data9.out | 3 ++ S2OJ/1058/data/problem.conf | 3 ++ 42 files changed, 195 insertions(+) create mode 100644 S2OJ/1058/1058.cpp create mode 100644 S2OJ/1058/data/data1.in create mode 100644 S2OJ/1058/data/data1.out create mode 100644 S2OJ/1058/data/data10.in create mode 100644 S2OJ/1058/data/data10.out create mode 100644 S2OJ/1058/data/data11.in create mode 100644 S2OJ/1058/data/data11.out create mode 100644 S2OJ/1058/data/data12.in create mode 100644 S2OJ/1058/data/data12.out create mode 100644 S2OJ/1058/data/data13.in create mode 100644 S2OJ/1058/data/data13.out create mode 100644 S2OJ/1058/data/data14.in create mode 100644 S2OJ/1058/data/data14.out create mode 100644 S2OJ/1058/data/data15.in create mode 100644 S2OJ/1058/data/data15.out create mode 100644 S2OJ/1058/data/data16.in create mode 100644 S2OJ/1058/data/data16.out create mode 100644 S2OJ/1058/data/data17.in create mode 100644 S2OJ/1058/data/data17.out create mode 100644 S2OJ/1058/data/data18.in create mode 100644 S2OJ/1058/data/data18.out create mode 100644 S2OJ/1058/data/data19.in create mode 100644 S2OJ/1058/data/data19.out create mode 100644 S2OJ/1058/data/data2.in create mode 100644 S2OJ/1058/data/data2.out create mode 100644 S2OJ/1058/data/data20.in create mode 100644 S2OJ/1058/data/data20.out create mode 100644 S2OJ/1058/data/data3.in create mode 100644 S2OJ/1058/data/data3.out create mode 100644 S2OJ/1058/data/data4.in create mode 100644 S2OJ/1058/data/data4.out create mode 100644 S2OJ/1058/data/data5.in create mode 100644 S2OJ/1058/data/data5.out create mode 100644 S2OJ/1058/data/data6.in create mode 100644 S2OJ/1058/data/data6.out create mode 100644 S2OJ/1058/data/data7.in create mode 100644 S2OJ/1058/data/data7.out create mode 100644 S2OJ/1058/data/data8.in create mode 100644 S2OJ/1058/data/data8.out create mode 100644 S2OJ/1058/data/data9.in create mode 100644 S2OJ/1058/data/data9.out create mode 100644 S2OJ/1058/data/problem.conf diff --git a/S2OJ/1058/1058.cpp b/S2OJ/1058/1058.cpp new file mode 100644 index 00000000..d91d2cdb --- /dev/null +++ b/S2OJ/1058/1058.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +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, + std::vector>, + auto(*)(std::pair, std::pair)->bool> +q([](std::pair a, std::pair 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(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(std::numeric_limits::max()), c[l] + c[r] - c[o.first]) : std::numeric_limits::max(); + c[l] = c[r] = std::numeric_limits::max(); + + q.emplace(o.first, c[o.first]); + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1058/data/data1.in b/S2OJ/1058/data/data1.in new file mode 100644 index 00000000..688ce6aa --- /dev/null +++ b/S2OJ/1058/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a057be2076d9b9de46d44bd8b4571be921471a57312322fad7cecd5d800cbd46 +size 992456 diff --git a/S2OJ/1058/data/data1.out b/S2OJ/1058/data/data1.out new file mode 100644 index 00000000..e28972cd --- /dev/null +++ b/S2OJ/1058/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccf6a7351c24e34105f3cb489be6656c03034b6fd62370e108161e6031b1e76b +size 10 diff --git a/S2OJ/1058/data/data10.in b/S2OJ/1058/data/data10.in new file mode 100644 index 00000000..3010888f --- /dev/null +++ b/S2OJ/1058/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edb327955e2e1deee5c872c896bc9b0892267994cae933e3f8213ab1046e8e2c +size 17 diff --git a/S2OJ/1058/data/data10.out b/S2OJ/1058/data/data10.out new file mode 100644 index 00000000..ef0c98e2 --- /dev/null +++ b/S2OJ/1058/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8bd5a23c3aef1243c78bac155b39b9d57a43d8c49665ccf6f42acf2992a94afa +size 11 diff --git a/S2OJ/1058/data/data11.in b/S2OJ/1058/data/data11.in new file mode 100644 index 00000000..cffc5c11 --- /dev/null +++ b/S2OJ/1058/data/data11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69f399ccef297c87296969c15bbe2368a9e27df503c020a04b69fca6b0642ed6 +size 45 diff --git a/S2OJ/1058/data/data11.out b/S2OJ/1058/data/data11.out new file mode 100644 index 00000000..dbd0b512 --- /dev/null +++ b/S2OJ/1058/data/data11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1ce0aa6fdf3cf349d773243dab9fbbe09d30619f38b0c1e8977e28c4f0bc495 +size 3 diff --git a/S2OJ/1058/data/data12.in b/S2OJ/1058/data/data12.in new file mode 100644 index 00000000..30695370 --- /dev/null +++ b/S2OJ/1058/data/data12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83dbc5ae60332e0f2161aa0c8fbdfc5020dabc345e4c764e0f647c28d89e0f87 +size 8003 diff --git a/S2OJ/1058/data/data12.out b/S2OJ/1058/data/data12.out new file mode 100644 index 00000000..d952ad86 --- /dev/null +++ b/S2OJ/1058/data/data12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e48e8997b9908557b7169b145cd868eef4244fa78142d901a83d2c2d957c1a7f +size 8 diff --git a/S2OJ/1058/data/data13.in b/S2OJ/1058/data/data13.in new file mode 100644 index 00000000..0cf84ffd --- /dev/null +++ b/S2OJ/1058/data/data13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e96b11c80139c0bfac3e379924e6eb2af0980b2558c33077ffac2050258f9f2 +size 105 diff --git a/S2OJ/1058/data/data13.out b/S2OJ/1058/data/data13.out new file mode 100644 index 00000000..53fbb8c9 --- /dev/null +++ b/S2OJ/1058/data/data13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37520f7622647f417ee6f3c00cfd78caeb131daa11202aad5fa392f4eca3a59d +size 4 diff --git a/S2OJ/1058/data/data14.in b/S2OJ/1058/data/data14.in new file mode 100644 index 00000000..afc3e0c2 --- /dev/null +++ b/S2OJ/1058/data/data14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44cf11c87fc63ab7b1d4fa36b9502c7a2cfc25971dcf230d6194453f497ffeb7 +size 981954 diff --git a/S2OJ/1058/data/data14.out b/S2OJ/1058/data/data14.out new file mode 100644 index 00000000..465bb42e --- /dev/null +++ b/S2OJ/1058/data/data14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:069a176ad853bc3f8d918c41ec21954812863065145042706da73930179dd0b9 +size 10 diff --git a/S2OJ/1058/data/data15.in b/S2OJ/1058/data/data15.in new file mode 100644 index 00000000..bdc4db8e --- /dev/null +++ b/S2OJ/1058/data/data15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0165e1579a669a3f41936f8933113c396e758a106412dada16f19f197fe791d3 +size 99237 diff --git a/S2OJ/1058/data/data15.out b/S2OJ/1058/data/data15.out new file mode 100644 index 00000000..bc0da224 --- /dev/null +++ b/S2OJ/1058/data/data15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d019c15163d06390dcb9e4d4b88c47f0e6cfd38d3bbe2953f083a57ebb2eca3 +size 10 diff --git a/S2OJ/1058/data/data16.in b/S2OJ/1058/data/data16.in new file mode 100644 index 00000000..abad7c80 --- /dev/null +++ b/S2OJ/1058/data/data16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1f85b58d1762863558de743b5ca6dd220e367c38ed36f6282831f5e3259336a +size 206 diff --git a/S2OJ/1058/data/data16.out b/S2OJ/1058/data/data16.out new file mode 100644 index 00000000..57aedecb --- /dev/null +++ b/S2OJ/1058/data/data16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1765141e7c1a47fe61ad08d1a3bbebefd11800a4f6992187987c1d5efdabeb3 +size 10 diff --git a/S2OJ/1058/data/data17.in b/S2OJ/1058/data/data17.in new file mode 100644 index 00000000..0abc4098 --- /dev/null +++ b/S2OJ/1058/data/data17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f47b8bc35583fbf784a1d947071b43927396add3574e9ba0664473775ef9ab7 +size 124 diff --git a/S2OJ/1058/data/data17.out b/S2OJ/1058/data/data17.out new file mode 100644 index 00000000..e1f1394d --- /dev/null +++ b/S2OJ/1058/data/data17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d909e88e7fa0c6e79055b361c918d4801bc157a1b9b680b4041f7f1c7a4590ba +size 4 diff --git a/S2OJ/1058/data/data18.in b/S2OJ/1058/data/data18.in new file mode 100644 index 00000000..1a442c86 --- /dev/null +++ b/S2OJ/1058/data/data18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57ec12fe14e205863065f00c2ba1f58080ea73986136af4b97b63ac37aac97e9 +size 992519 diff --git a/S2OJ/1058/data/data18.out b/S2OJ/1058/data/data18.out new file mode 100644 index 00000000..7b875dbc --- /dev/null +++ b/S2OJ/1058/data/data18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7d0bed096f027628a0279a8b5244bb7396f3749362befcfac78b786a41030e2 +size 10 diff --git a/S2OJ/1058/data/data19.in b/S2OJ/1058/data/data19.in new file mode 100644 index 00000000..3199202e --- /dev/null +++ b/S2OJ/1058/data/data19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:693d0843a5fb8f253869a817886e0a2c2ebeb85470bde166a6a27d3320ed5df1 +size 974108 diff --git a/S2OJ/1058/data/data19.out b/S2OJ/1058/data/data19.out new file mode 100644 index 00000000..0428468b --- /dev/null +++ b/S2OJ/1058/data/data19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b727aa09cfb4bc823b90d9ed0d9a6304d5532e6b639e56d5ce668995ac203dbf +size 10 diff --git a/S2OJ/1058/data/data2.in b/S2OJ/1058/data/data2.in new file mode 100644 index 00000000..b818fffb --- /dev/null +++ b/S2OJ/1058/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:902bb088365dec6c36b6181bd49d8dac421e6da067d41435374b4df3739818c7 +size 992482 diff --git a/S2OJ/1058/data/data2.out b/S2OJ/1058/data/data2.out new file mode 100644 index 00000000..1f0e3fdb --- /dev/null +++ b/S2OJ/1058/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e3a0a369423b139c0719883020c9294a89664e22ae931595bc303df978571e +size 6 diff --git a/S2OJ/1058/data/data20.in b/S2OJ/1058/data/data20.in new file mode 100644 index 00000000..cfc22075 --- /dev/null +++ b/S2OJ/1058/data/data20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5c638b100ca4612f06c108324a2845fbb59f8b2ac48abc7568417e6d317dadd +size 801 diff --git a/S2OJ/1058/data/data20.out b/S2OJ/1058/data/data20.out new file mode 100644 index 00000000..678e5f3b --- /dev/null +++ b/S2OJ/1058/data/data20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a254305c0477c2c3234bfa383ddfe05e9fb21efa6251887cb16b351230af054b +size 8 diff --git a/S2OJ/1058/data/data3.in b/S2OJ/1058/data/data3.in new file mode 100644 index 00000000..e0886e1a --- /dev/null +++ b/S2OJ/1058/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5081ca5aa95ccd103a809550f51ceeb5eda6aecf6eb1f419685eec030ceae122 +size 496163 diff --git a/S2OJ/1058/data/data3.out b/S2OJ/1058/data/data3.out new file mode 100644 index 00000000..2d83818f --- /dev/null +++ b/S2OJ/1058/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbe05695b93c70c54d159226d96ca91680d174b266e68114c391a755ab536197 +size 7 diff --git a/S2OJ/1058/data/data4.in b/S2OJ/1058/data/data4.in new file mode 100644 index 00000000..4379ff87 --- /dev/null +++ b/S2OJ/1058/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87fe8b296cb237979f5ba230a5d596cdb98b014acf1445743b4ef7816aa0c6d9 +size 177481 diff --git a/S2OJ/1058/data/data4.out b/S2OJ/1058/data/data4.out new file mode 100644 index 00000000..798ee5c4 --- /dev/null +++ b/S2OJ/1058/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa5c5a6a1042670389d066041881852f5da92dfa09fb852d8489b66c5273e484 +size 7 diff --git a/S2OJ/1058/data/data5.in b/S2OJ/1058/data/data5.in new file mode 100644 index 00000000..c5629de2 --- /dev/null +++ b/S2OJ/1058/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45d6186b12f616216b1066483ee5a9348df49b03a50ff76debe9d61f123fb664 +size 992519 diff --git a/S2OJ/1058/data/data5.out b/S2OJ/1058/data/data5.out new file mode 100644 index 00000000..ecb5302f --- /dev/null +++ b/S2OJ/1058/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0079ddd7ee3ad8da4d252c79ecf2b8a066c62516f82cdc37f8b3a6a39ba0b7b4 +size 10 diff --git a/S2OJ/1058/data/data6.in b/S2OJ/1058/data/data6.in new file mode 100644 index 00000000..3f90fb54 --- /dev/null +++ b/S2OJ/1058/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8c78c1f68daf50aab5087fa2a69e58672fd8e942db4ac89fd25087d1efd8624 +size 61 diff --git a/S2OJ/1058/data/data6.out b/S2OJ/1058/data/data6.out new file mode 100644 index 00000000..49cf624d --- /dev/null +++ b/S2OJ/1058/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff5fcd5b7adc5169067e6cb21ea8d10a3886d67b661f00dc3967902e5637596b +size 5 diff --git a/S2OJ/1058/data/data7.in b/S2OJ/1058/data/data7.in new file mode 100644 index 00000000..5ef77ab8 --- /dev/null +++ b/S2OJ/1058/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb21f0ee8d1fedcb26ba5d917832f2a7b95acc73d2dd65e031fab04552557ca4 +size 683 diff --git a/S2OJ/1058/data/data7.out b/S2OJ/1058/data/data7.out new file mode 100644 index 00000000..e16e1bae --- /dev/null +++ b/S2OJ/1058/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f21676f71bea3ee9e29edb6ca2ee7e099d35e7e6fe8059a1fc8368dbe61607d0 +size 7 diff --git a/S2OJ/1058/data/data8.in b/S2OJ/1058/data/data8.in new file mode 100644 index 00000000..270d163e --- /dev/null +++ b/S2OJ/1058/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f82c9ef25edcecc66b6e9d087558824c91e105fe33bceb1bbc3b9f8de6e5ccf0 +size 13861 diff --git a/S2OJ/1058/data/data8.out b/S2OJ/1058/data/data8.out new file mode 100644 index 00000000..bf6ac7b7 --- /dev/null +++ b/S2OJ/1058/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c4e06d3fb7e1d943b78fcc760b15df88e4b0bd7b88f4a43194d26ae0fd04ef4 +size 7 diff --git a/S2OJ/1058/data/data9.in b/S2OJ/1058/data/data9.in new file mode 100644 index 00000000..db487d3c --- /dev/null +++ b/S2OJ/1058/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34ba606c06b3213b8fec2e44d9aaec0db871d7b7288d37aea89733b5914e29fa +size 99253 diff --git a/S2OJ/1058/data/data9.out b/S2OJ/1058/data/data9.out new file mode 100644 index 00000000..30be2e31 --- /dev/null +++ b/S2OJ/1058/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73fa73708fd88d2c75b8da351b8739f373e72e31f73fedd3039b51116aa22c33 +size 10 diff --git a/S2OJ/1058/data/problem.conf b/S2OJ/1058/data/problem.conf new file mode 100644 index 00000000..f27e8d00 --- /dev/null +++ b/S2OJ/1058/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:caa259d37aa92ad823095ebde781e74362ee89209eb83e29be33ec2d4bbf4305 +size 193