diff --git a/BZOJ/1584/1584.cpp b/BZOJ/1584/1584.cpp new file mode 100644 index 00000000..9159e6df --- /dev/null +++ b/BZOJ/1584/1584.cpp @@ -0,0 +1,53 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 40005; + +int n, m, t, p[N], pre[N], lst[N], nxt[N], pos[N], cnt[N], f[N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + std::fill(f, f + 1 + n, 0x3f3f3f3f); + + for (int i = 1; i <= n; i++) { + cin >> p[i]; + + pre[i] = lst[p[i]]; + nxt[lst[p[i]]] = i; + lst[p[i]] = i; + nxt[i] = n + 1; + } + + t = std::sqrt(n); + f[1] = 1; + + for (int i = 1; i <= t; i++) { + pos[i] = 1; + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= t; j++) { + if (pre[i] < pos[j]) cnt[j]++; + + if (cnt[j] > j) { + cnt[j]--; + + while (nxt[pos[j]++] < i) {} + } + + f[i] = std::min(f[i], f[pos[j] - 1] + (int)std::pow(j, 2)); + } + } + + cout << f[n] << endl; + + return 0; +} diff --git a/BZOJ/1584/data/1.in b/BZOJ/1584/data/1.in new file mode 100644 index 00000000..7e0a7fff --- /dev/null +++ b/BZOJ/1584/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3104a911f73fb243a0a1be20ec108753a9d440c138ba2af1c1bac2003ee45f7e +size 3130 diff --git a/BZOJ/1584/data/1.out b/BZOJ/1584/data/1.out new file mode 100644 index 00000000..a21a76ba --- /dev/null +++ b/BZOJ/1584/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7a72f7e1677172eec67fbe4378c722fda94651e94b428f448263e02bc287841 +size 4 diff --git a/BZOJ/1584/data/10.in b/BZOJ/1584/data/10.in new file mode 100644 index 00000000..186bbcd4 --- /dev/null +++ b/BZOJ/1584/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b4d4431f26f823197c1bfeb5342dc35a4ebce021599c74ad65fcecca82bf531 +size 198648 diff --git a/BZOJ/1584/data/10.out b/BZOJ/1584/data/10.out new file mode 100644 index 00000000..545ebdae --- /dev/null +++ b/BZOJ/1584/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7e91b12fda4df08700277e1ab482ff7705f0774c1b137df74a290b1afb72c91 +size 6 diff --git a/BZOJ/1584/data/2.in b/BZOJ/1584/data/2.in new file mode 100644 index 00000000..9f8349ca --- /dev/null +++ b/BZOJ/1584/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c441fe468c1266bc967d780b959c5a85e69b8e8328b92ac58c66d1dac69a6407 +size 136992 diff --git a/BZOJ/1584/data/2.out b/BZOJ/1584/data/2.out new file mode 100644 index 00000000..9db3403a --- /dev/null +++ b/BZOJ/1584/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49412259fa69a980393d2e30d2971f32792d035cc129c1dd5d3e78229169c1b2 +size 5 diff --git a/BZOJ/1584/data/3.in b/BZOJ/1584/data/3.in new file mode 100644 index 00000000..cb50da24 --- /dev/null +++ b/BZOJ/1584/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47b7f5b76f5c5508571f1181a522775633ee8b1fe9acaec0205f4a5426a4d249 +size 308 diff --git a/BZOJ/1584/data/3.out b/BZOJ/1584/data/3.out new file mode 100644 index 00000000..ad2c816c --- /dev/null +++ b/BZOJ/1584/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3840bc236ee03aacbb1ef7d5108ddfa347c59f10b68d4174affbb53140f31273 +size 3 diff --git a/BZOJ/1584/data/4.in b/BZOJ/1584/data/4.in new file mode 100644 index 00000000..6bd2a6c4 --- /dev/null +++ b/BZOJ/1584/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da72010891e30738ee8534b746a3f3110f0917daaa4c97ad30c87a7a207f309b +size 25 diff --git a/BZOJ/1584/data/4.out b/BZOJ/1584/data/4.out new file mode 100644 index 00000000..f2baf931 --- /dev/null +++ b/BZOJ/1584/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10159baf262b43a92d95db59dae1f72c645127301661e0a3ce4e38b295a97c58 +size 2 diff --git a/BZOJ/1584/data/5.in b/BZOJ/1584/data/5.in new file mode 100644 index 00000000..3cb42120 --- /dev/null +++ b/BZOJ/1584/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0332668b5a85d0ce0bdeb4c073bdd58ad99c983e7dc01f06ddb8a424f59b202f +size 168817 diff --git a/BZOJ/1584/data/5.out b/BZOJ/1584/data/5.out new file mode 100644 index 00000000..fee53f67 --- /dev/null +++ b/BZOJ/1584/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5372588733824ecf5744e694f5d12b57d33e19ff1fd8b88a7e723e7426eea890 +size 6 diff --git a/BZOJ/1584/data/6.in b/BZOJ/1584/data/6.in new file mode 100644 index 00000000..cc376d31 --- /dev/null +++ b/BZOJ/1584/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:999708309bf02071ee512bf7249921e5c4708de2e21fee37a3a315fb0b9529ac +size 31 diff --git a/BZOJ/1584/data/6.out b/BZOJ/1584/data/6.out new file mode 100644 index 00000000..c7967cd5 --- /dev/null +++ b/BZOJ/1584/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25d4f2a86deb5e2574bb3210b67bb24fcc4afb19f93a7b65a057daa874a9d18e +size 3 diff --git a/BZOJ/1584/data/7.in b/BZOJ/1584/data/7.in new file mode 100644 index 00000000..5abb494b --- /dev/null +++ b/BZOJ/1584/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d200369f34e3100e48f0601793e67a1545f561901de2e656665e7d5dc2d4115 +size 231401 diff --git a/BZOJ/1584/data/7.out b/BZOJ/1584/data/7.out new file mode 100644 index 00000000..66f75f59 --- /dev/null +++ b/BZOJ/1584/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee89a3a3f5383053f808e4826cbfe4d333cd016c8ba77229670aae3b4e21cd19 +size 6 diff --git a/BZOJ/1584/data/8.in b/BZOJ/1584/data/8.in new file mode 100644 index 00000000..632b5d07 --- /dev/null +++ b/BZOJ/1584/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbf7235f43a3dc3bfc53da67f7824f72f76ef6dda0ce2bc8daafd5502e964e55 +size 108762 diff --git a/BZOJ/1584/data/8.out b/BZOJ/1584/data/8.out new file mode 100644 index 00000000..3fb0360e --- /dev/null +++ b/BZOJ/1584/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c061381b2aa04b79bd8c1cd939d181aefaa1643d89eb80873c364ffccec858c7 +size 5 diff --git a/BZOJ/1584/data/9.in b/BZOJ/1584/data/9.in new file mode 100644 index 00000000..443a555c --- /dev/null +++ b/BZOJ/1584/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b3ea190ac61b9a0009bbaa465efad1e159714b93ff3725799c965d6dcf818e3 +size 23843 diff --git a/BZOJ/1584/data/9.out b/BZOJ/1584/data/9.out new file mode 100644 index 00000000..8a8c8b9b --- /dev/null +++ b/BZOJ/1584/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:229ea49e314013a163acaca41eef5d259a52b638f0fa7ef275eb33324348ec6b +size 5