0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00

#1611. 【2022.10.9 联考】和为贵(sum)

https://sjzezoj.com/submission/59820
This commit is contained in:
Baoshuo Ren 2022-10-09 16:57:02 +08:00
parent 125c195826
commit 17c13ed975
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
26 changed files with 144 additions and 0 deletions

69
S2OJ/1611/1611.cpp Normal file
View File

@ -0,0 +1,69 @@
#include <iostream>
#include <algorithm>
#include <iterator>
#include <set>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5,
K = 55;
int n, k, a[N], pos[N], pre[N][K], nxt[N][K], prev[N], next[N];
long long ans;
std::set<int> set;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pos[a[i]] = i;
}
for (int i = n; i; i--) {
int p = pos[i];
auto it = set.lower_bound(p);
std::fill_n(pre[p], K, 0);
std::fill_n(nxt[p], K, n + 1);
pre[p][0] = nxt[p][0] = p;
if (it != set.end()) {
prev[*it] = p;
next[p] = *it;
for (int j = *it, l = 1; j && l <= k; j = next[j], l++) {
nxt[p][l] = j;
}
}
if (it != set.begin()) {
it--;
prev[p] = *it;
next[*it] = p;
for (int j = *it, l = 1; j && l <= k; j = prev[j], l++) {
pre[p][l] = j;
}
}
set.insert(p);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
ans += static_cast<long long>(a[i]) * (pre[i][j - 1] - pre[i][j]) * (nxt[i][k - j + 1] - nxt[i][k - j]);
}
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1611/data/ex_sum1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/ex_sum1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/ex_sum2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/ex_sum2.out (Stored with Git LFS) Normal file

Binary file not shown.

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

Binary file not shown.

BIN
S2OJ/1611/data/sum1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1611/data/sum9.out (Stored with Git LFS) Normal file

Binary file not shown.