diff --git a/S2OJ/1611/1611.cpp b/S2OJ/1611/1611.cpp new file mode 100644 index 00000000..b188d486 --- /dev/null +++ b/S2OJ/1611/1611.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include + +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 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(a[i]) * (pre[i][j - 1] - pre[i][j]) * (nxt[i][k - j + 1] - nxt[i][k - j]); + } + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1611/data/ex_sum1.in b/S2OJ/1611/data/ex_sum1.in new file mode 100644 index 00000000..2cf95505 --- /dev/null +++ b/S2OJ/1611/data/ex_sum1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac684831f0bf21b79384d6b26d140a64707985fd640e5f78b02da0632d43fd50 +size 14 diff --git a/S2OJ/1611/data/ex_sum1.out b/S2OJ/1611/data/ex_sum1.out new file mode 100644 index 00000000..8da2bb0d --- /dev/null +++ b/S2OJ/1611/data/ex_sum1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4ccd05b3271c386ee55d9876c7450012a3b361e5065c09dc22075e38b3cc35c +size 3 diff --git a/S2OJ/1611/data/ex_sum2.in b/S2OJ/1611/data/ex_sum2.in new file mode 100644 index 00000000..294f9794 --- /dev/null +++ b/S2OJ/1611/data/ex_sum2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:401d11b3e0b6f0c96e9f0340c736f9b3ee39e3b639b151e087175828c76d7a4c +size 3901 diff --git a/S2OJ/1611/data/ex_sum2.out b/S2OJ/1611/data/ex_sum2.out new file mode 100644 index 00000000..326310cd --- /dev/null +++ b/S2OJ/1611/data/ex_sum2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d2a7d0e687189aeb37fe836e5fe78165b007ea76e23a4074438a97accecacc9 +size 10 diff --git a/S2OJ/1611/data/problem.conf b/S2OJ/1611/data/problem.conf new file mode 100644 index 00000000..f3d7f9b6 --- /dev/null +++ b/S2OJ/1611/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29cae276597f68955757936c8483675bae50265660478d4444c458a60c40f523 +size 175 diff --git a/S2OJ/1611/data/sum1.in b/S2OJ/1611/data/sum1.in new file mode 100644 index 00000000..3a9159b7 --- /dev/null +++ b/S2OJ/1611/data/sum1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:606e9982fea9befacd531c86ee3496fe00233a84a0cc5c6c8354c8a0ac044f98 +size 299 diff --git a/S2OJ/1611/data/sum1.out b/S2OJ/1611/data/sum1.out new file mode 100644 index 00000000..51fdb11c --- /dev/null +++ b/S2OJ/1611/data/sum1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:337613f04abe06de1fcf21e0157efab19d48632f3bf7fc146e0a35d14fe43bac +size 6 diff --git a/S2OJ/1611/data/sum10.in b/S2OJ/1611/data/sum10.in new file mode 100644 index 00000000..345bb11f --- /dev/null +++ b/S2OJ/1611/data/sum10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98ad96dc1270454bdca52d5118419d5a9bdfbbc9204efd6ff016d5a527801d03 +size 3388905 diff --git a/S2OJ/1611/data/sum10.out b/S2OJ/1611/data/sum10.out new file mode 100644 index 00000000..2728212e --- /dev/null +++ b/S2OJ/1611/data/sum10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ae3a30bdc5c3966dadfd2927ade26caaa52b7494e5682bc7db6f88f260b60d2 +size 18 diff --git a/S2OJ/1611/data/sum2.in b/S2OJ/1611/data/sum2.in new file mode 100644 index 00000000..4b69473e --- /dev/null +++ b/S2OJ/1611/data/sum2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f71f2d15f719878ee6f0af469eed45019c68472a6cb68b25e83576c746fe137d +size 299 diff --git a/S2OJ/1611/data/sum2.out b/S2OJ/1611/data/sum2.out new file mode 100644 index 00000000..36c9d0a9 --- /dev/null +++ b/S2OJ/1611/data/sum2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcbb2a077a09f5994fe677f859872e418f922a51f2cabd82376be68261d22679 +size 6 diff --git a/S2OJ/1611/data/sum3.in b/S2OJ/1611/data/sum3.in new file mode 100644 index 00000000..d1ceacfb --- /dev/null +++ b/S2OJ/1611/data/sum3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93b3491ab13613b84348cb77d75e4c10fbf3175ffc70462fcfeb213c1b7f8a26 +size 3901 diff --git a/S2OJ/1611/data/sum3.out b/S2OJ/1611/data/sum3.out new file mode 100644 index 00000000..fcd4d5f4 --- /dev/null +++ b/S2OJ/1611/data/sum3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59043d2f4a7a400e9f9a1721e36c6943531dd9300b5d60511dd2de002e93c307 +size 10 diff --git a/S2OJ/1611/data/sum4.in b/S2OJ/1611/data/sum4.in new file mode 100644 index 00000000..42294ed3 --- /dev/null +++ b/S2OJ/1611/data/sum4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8fc27c385e094b6a2107b2e46c757f242d30ebbf8e5e55c8307a0cc96f7299c +size 3901 diff --git a/S2OJ/1611/data/sum4.out b/S2OJ/1611/data/sum4.out new file mode 100644 index 00000000..b864f7c9 --- /dev/null +++ b/S2OJ/1611/data/sum4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be688d7d3889afb05972b95defd5a9d6729370b36f9744602d390a7270708916 +size 10 diff --git a/S2OJ/1611/data/sum5.in b/S2OJ/1611/data/sum5.in new file mode 100644 index 00000000..7235be61 --- /dev/null +++ b/S2OJ/1611/data/sum5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:482328b093fce2e8ab98c7fb14dd2757c917ee5ad97dae417cd9d9b0c643ab6d +size 3388904 diff --git a/S2OJ/1611/data/sum5.out b/S2OJ/1611/data/sum5.out new file mode 100644 index 00000000..864d74d1 --- /dev/null +++ b/S2OJ/1611/data/sum5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81fb5c55ae3bd98a41648ef86f1db0834ed64d9c62cd3ace47050f85ed4aaba9 +size 18 diff --git a/S2OJ/1611/data/sum6.in b/S2OJ/1611/data/sum6.in new file mode 100644 index 00000000..aae760d4 --- /dev/null +++ b/S2OJ/1611/data/sum6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de7f35136c49960fd1bf7dc551ec72250d81aeda99a8fdfe735348652e455db4 +size 3388904 diff --git a/S2OJ/1611/data/sum6.out b/S2OJ/1611/data/sum6.out new file mode 100644 index 00000000..086c2750 --- /dev/null +++ b/S2OJ/1611/data/sum6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3c6179cf37c5631189b54ad3b970ba1409e6ad146aec44afb7f6ba39d81829b +size 18 diff --git a/S2OJ/1611/data/sum7.in b/S2OJ/1611/data/sum7.in new file mode 100644 index 00000000..5742a2bd --- /dev/null +++ b/S2OJ/1611/data/sum7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b0d1a27cfc8a03e4ffb9a5c9db79df8c49d7ab21bb1fddba354d19724a33f82 +size 288903 diff --git a/S2OJ/1611/data/sum7.out b/S2OJ/1611/data/sum7.out new file mode 100644 index 00000000..1d7fccbb --- /dev/null +++ b/S2OJ/1611/data/sum7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8642bb815f48dafdbabb80e42a7dd18d945bd3ed7bb04d182aaa0b2748cc5cb +size 15 diff --git a/S2OJ/1611/data/sum8.in b/S2OJ/1611/data/sum8.in new file mode 100644 index 00000000..fac8f2f3 --- /dev/null +++ b/S2OJ/1611/data/sum8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdca6e5ae0e0c9a29576009063b47955476daf24baa500464e539966685a9c4e +size 288903 diff --git a/S2OJ/1611/data/sum8.out b/S2OJ/1611/data/sum8.out new file mode 100644 index 00000000..b09a2ed4 --- /dev/null +++ b/S2OJ/1611/data/sum8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0fbe335c3eb843c8bce04bbd331a3564369839ff3ff9fa78be2b5f3d399c9c6 +size 15 diff --git a/S2OJ/1611/data/sum9.in b/S2OJ/1611/data/sum9.in new file mode 100644 index 00000000..c2b3c71f --- /dev/null +++ b/S2OJ/1611/data/sum9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca7673165890f0475f0034bab5c0b8cf4cf1b94b5f8caa0ab178aca4471cc2b5 +size 3388905 diff --git a/S2OJ/1611/data/sum9.out b/S2OJ/1611/data/sum9.out new file mode 100644 index 00000000..6fce1b42 --- /dev/null +++ b/S2OJ/1611/data/sum9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b67368bf2f16d3fab44cc29c17a32a7e9407e51e5d636ef6848b59b39b9b8855 +size 18