diff --git a/S2OJ/1812/1812.cpp b/S2OJ/1812/1812.cpp new file mode 100644 index 00000000..dcd5c068 --- /dev/null +++ b/S2OJ/1812/1812.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e4 + 5; +const int INF = 0x3f3f3f3f; + +template +struct Max { + T operator()(T a, T b) const { + return std::max(a, b); + } +}; + +template +struct Min { + T operator()(T a, T b) const { + return std::min(a, b); + } +}; + +template > +class BIT { + private: + T default_val; + T c[N]; + + unsigned lowbit(unsigned x) { + return x & -x; + } + + public: + BIT(const T& init_val = 0) + : default_val(init_val) { + std::fill(std::begin(c), std::end(c), init_val); + } + + void add(unsigned x, T v) { + for (; x < N; x += lowbit(x)) { + c[x] = Operator()(c[x], v); + } + } + + T query(T x) { + T res = default_val; + + for (; x; x -= lowbit(x)) { + res = Operator()(res, c[x]); + } + + return res; + } +}; + +int n, k, a[N], s[N]; + +bool check(int x) { + int res_min = 0, + res_max = 0; + std::vector nums; + BIT> bit_max(-INF); + BIT> bit_min(INF); + + std::copy(s + 1, s + 1 + n, std::back_inserter(nums)); + std::transform(nums.begin(), nums.end(), nums.begin(), std::bind(std::minus(), std::placeholders::_1, x)); + std::copy(s, s + n, std::back_inserter(nums)); + std::sort(nums.begin(), nums.end()); + nums.erase(std::unique(nums.begin(), nums.end()), nums.end()); + + int pos = nums.size() - (std::lower_bound(nums.begin(), nums.end(), 0) - nums.begin() + 1) + 1; + + bit_min.add(pos, 0); + bit_max.add(pos, 0); + + for (int i = 1; i <= n; i++) { + pos = nums.size() - (std::lower_bound(nums.begin(), nums.end(), s[i] - x) - nums.begin() + 1) + 1; + res_min = bit_min.query(pos); + res_max = bit_max.query(pos); + + if (i < n) { + pos = nums.size() - (std::lower_bound(nums.begin(), nums.end(), s[i]) - nums.begin() + 1) + 1; + bit_min.add(pos, res_min + 1); + bit_max.add(pos, res_max + 1); + } + } + + return ++res_min <= k && k <= ++res_max; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> k; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + std::partial_sum(a + 1, a + 1 + n, s + 1); + + int l = -INF, + r = INF, + ans = 0; + + while (l <= r) { + int mid = (l + r) >> 1; + + if (check(mid)) { + ans = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1812/data/divide1.in b/S2OJ/1812/data/divide1.in new file mode 100644 index 00000000..7c6582f4 --- /dev/null +++ b/S2OJ/1812/data/divide1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94c0240a36477e2c0beed845a15c0506f0649c91781789af892726b3beb4fea2 +size 438 diff --git a/S2OJ/1812/data/divide1.out b/S2OJ/1812/data/divide1.out new file mode 100644 index 00000000..ce0f30b0 --- /dev/null +++ b/S2OJ/1812/data/divide1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:877a8799041017f1719854e4e295c6dca56cd1cf1b1914d1bfed9281f7fc2686 +size 3 diff --git a/S2OJ/1812/data/divide10.in b/S2OJ/1812/data/divide10.in new file mode 100644 index 00000000..92d575e3 --- /dev/null +++ b/S2OJ/1812/data/divide10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c23170fee6a73aeb3d7f2d44ae2a385426df61f49f7f876fea3b4ab5144c8ca8 +size 135912 diff --git a/S2OJ/1812/data/divide10.out b/S2OJ/1812/data/divide10.out new file mode 100644 index 00000000..0236a05e --- /dev/null +++ b/S2OJ/1812/data/divide10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2320d441167e193ac1298474439d6394f327d0c105714ed00f9c9e0b3353abb5 +size 7 diff --git a/S2OJ/1812/data/divide11.in b/S2OJ/1812/data/divide11.in new file mode 100644 index 00000000..fbf9c72b --- /dev/null +++ b/S2OJ/1812/data/divide11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df7490ddcaf278c1f30b0573c6fab4418fa9c09a78e6b8017236710622372d5e +size 142056 diff --git a/S2OJ/1812/data/divide11.out b/S2OJ/1812/data/divide11.out new file mode 100644 index 00000000..9fd90940 --- /dev/null +++ b/S2OJ/1812/data/divide11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92b03f4e4339a6bd02de2362d220ecf8413e52cece86e9d2e2bccbe5dc169821 +size 7 diff --git a/S2OJ/1812/data/divide12.in b/S2OJ/1812/data/divide12.in new file mode 100644 index 00000000..dc2532ce --- /dev/null +++ b/S2OJ/1812/data/divide12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9f10f7c4b86495b939a2b295a5f9203c18129853e204c290f3fe1c32c24ee1fd +size 195604 diff --git a/S2OJ/1812/data/divide12.out b/S2OJ/1812/data/divide12.out new file mode 100644 index 00000000..ed4e4f75 --- /dev/null +++ b/S2OJ/1812/data/divide12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06e29f8ae349c5574a0deaf76327db6f7431691e281f6f56f1f3b61da1f6a584 +size 7 diff --git a/S2OJ/1812/data/divide13.in b/S2OJ/1812/data/divide13.in new file mode 100644 index 00000000..906267d4 --- /dev/null +++ b/S2OJ/1812/data/divide13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15f9c4112b3fb21ee2ab53b5edfe3c6488bfbe732cc3471d2535f8534508e20b +size 241450 diff --git a/S2OJ/1812/data/divide13.out b/S2OJ/1812/data/divide13.out new file mode 100644 index 00000000..4c82fc03 --- /dev/null +++ b/S2OJ/1812/data/divide13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54c2a8cd4c3f80e60f7ce65227411f48bb1c52aeeb1db93163234a5634855b2c +size 6 diff --git a/S2OJ/1812/data/divide14.in b/S2OJ/1812/data/divide14.in new file mode 100644 index 00000000..24e8e305 --- /dev/null +++ b/S2OJ/1812/data/divide14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e63df0d8cee8b68169d50862d677e5645cc141d898c3b7c58a1380a3b7e5accc +size 229712 diff --git a/S2OJ/1812/data/divide14.out b/S2OJ/1812/data/divide14.out new file mode 100644 index 00000000..3f506c5e --- /dev/null +++ b/S2OJ/1812/data/divide14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdf20f9221e7b9d6c714cd736e940cdbd3372b67bbb6d11eedbfbb74bbbd2d5b +size 7 diff --git a/S2OJ/1812/data/divide15.in b/S2OJ/1812/data/divide15.in new file mode 100644 index 00000000..e6ba753e --- /dev/null +++ b/S2OJ/1812/data/divide15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa549ffa444ae0889e585d7701b98a13da279f1bef34463a36c3a2825b4be398 +size 202185 diff --git a/S2OJ/1812/data/divide15.out b/S2OJ/1812/data/divide15.out new file mode 100644 index 00000000..bf907069 --- /dev/null +++ b/S2OJ/1812/data/divide15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c79d125866ae888c6d4f1bc497885523dccfa03980276c436422f0a2d4f93c96 +size 7 diff --git a/S2OJ/1812/data/divide16.in b/S2OJ/1812/data/divide16.in new file mode 100644 index 00000000..e7f2a008 --- /dev/null +++ b/S2OJ/1812/data/divide16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf0588457bceb135811f67d92782307a7e76957d25c7f6c4975e914b8a96bc42 +size 220986 diff --git a/S2OJ/1812/data/divide16.out b/S2OJ/1812/data/divide16.out new file mode 100644 index 00000000..0d016981 --- /dev/null +++ b/S2OJ/1812/data/divide16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ab9df248aaef32d661a34a6b59b707dbd00b2cb8b7223958bfd5921d4b336ea +size 8 diff --git a/S2OJ/1812/data/divide17.in b/S2OJ/1812/data/divide17.in new file mode 100644 index 00000000..6b2c3337 --- /dev/null +++ b/S2OJ/1812/data/divide17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab8d35a2308a708d680e2b47c50dfd1656b8bd244076dddb13937d490ca23459 +size 306344 diff --git a/S2OJ/1812/data/divide17.out b/S2OJ/1812/data/divide17.out new file mode 100644 index 00000000..e1f5a842 --- /dev/null +++ b/S2OJ/1812/data/divide17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4d5fb1c6b8d9b00b293d13a6ea329fa0ad63494ef36c3e0082baeb2384ad1de +size 6 diff --git a/S2OJ/1812/data/divide18.in b/S2OJ/1812/data/divide18.in new file mode 100644 index 00000000..d7248949 --- /dev/null +++ b/S2OJ/1812/data/divide18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b64dd951d21e15506c4e798c164752600e4a252f61b5b3acb1ddd17a921d6e65 +size 306382 diff --git a/S2OJ/1812/data/divide18.out b/S2OJ/1812/data/divide18.out new file mode 100644 index 00000000..82f674d8 --- /dev/null +++ b/S2OJ/1812/data/divide18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a5dd51aa6ca1d5e897da22f2091674deaecf034f3924b2a7e959901f559cfb9 +size 6 diff --git a/S2OJ/1812/data/divide19.in b/S2OJ/1812/data/divide19.in new file mode 100644 index 00000000..fecb2a0a --- /dev/null +++ b/S2OJ/1812/data/divide19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:daf228eb52068bd6997ebfa2ad601d8deb52874f12471d57149e8940259785a7 +size 306751 diff --git a/S2OJ/1812/data/divide19.out b/S2OJ/1812/data/divide19.out new file mode 100644 index 00000000..23c920e0 --- /dev/null +++ b/S2OJ/1812/data/divide19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11f2c5e2f072b360b2021fe7444fced5c4a448044bacdb96d23323c518a4ad19 +size 5 diff --git a/S2OJ/1812/data/divide2.in b/S2OJ/1812/data/divide2.in new file mode 100644 index 00000000..d13c5591 --- /dev/null +++ b/S2OJ/1812/data/divide2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:300330f4e6a3fb3135da53fea0cf59a44bd0499a8142ebba6e9f8b5dcb6ec608 +size 438 diff --git a/S2OJ/1812/data/divide2.out b/S2OJ/1812/data/divide2.out new file mode 100644 index 00000000..2614851d --- /dev/null +++ b/S2OJ/1812/data/divide2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d92c61b32619f9f894b657941a45489569d9d4e48ddd9e2d0b2f375ecd28299c +size 4 diff --git a/S2OJ/1812/data/divide20.in b/S2OJ/1812/data/divide20.in new file mode 100644 index 00000000..63dca9a0 --- /dev/null +++ b/S2OJ/1812/data/divide20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:507e43b5e3bbaf37455fc3524bf14d1d87cd1c548b6fc83fa40679e4dfc07f7a +size 306579 diff --git a/S2OJ/1812/data/divide20.out b/S2OJ/1812/data/divide20.out new file mode 100644 index 00000000..70d791ac --- /dev/null +++ b/S2OJ/1812/data/divide20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c61da9619b9157df31d53208d27934a2d243e6ef97c269d73baeddf1da87146 +size 6 diff --git a/S2OJ/1812/data/divide3.in b/S2OJ/1812/data/divide3.in new file mode 100644 index 00000000..dc1cc035 --- /dev/null +++ b/S2OJ/1812/data/divide3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef05836e939d99baf34b9abfcb2687e63dd0829f6856862010cb2f39e48590dc +size 437 diff --git a/S2OJ/1812/data/divide3.out b/S2OJ/1812/data/divide3.out new file mode 100644 index 00000000..b5cc0e69 --- /dev/null +++ b/S2OJ/1812/data/divide3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f82e52c0de8601ad3400aa80af6abb724eb1e04ab3b64b7310c8776017b82dc +size 4 diff --git a/S2OJ/1812/data/divide4.in b/S2OJ/1812/data/divide4.in new file mode 100644 index 00000000..fdb0591e --- /dev/null +++ b/S2OJ/1812/data/divide4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91c4e9d93ac9667373b2fd779ef1bf318e1ccbb384286e17a94c562ec383b802 +size 427 diff --git a/S2OJ/1812/data/divide4.out b/S2OJ/1812/data/divide4.out new file mode 100644 index 00000000..80ed2215 --- /dev/null +++ b/S2OJ/1812/data/divide4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37aeed46a172d08e210fed9c4ad8922aeaa0d7a52faaee0fada64760d1741dd0 +size 4 diff --git a/S2OJ/1812/data/divide5.in b/S2OJ/1812/data/divide5.in new file mode 100644 index 00000000..113c1772 --- /dev/null +++ b/S2OJ/1812/data/divide5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45f29f9a6e4ced6dd7a3fea7def761ec520906ed782a86009df41a41b0be3ed7 +size 83313 diff --git a/S2OJ/1812/data/divide5.out b/S2OJ/1812/data/divide5.out new file mode 100644 index 00000000..18e2a1f7 --- /dev/null +++ b/S2OJ/1812/data/divide5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63e65d4fcde9413e81c2b6a515d3875021ae9097923f0338d908f3a0c8529b63 +size 7 diff --git a/S2OJ/1812/data/divide6.in b/S2OJ/1812/data/divide6.in new file mode 100644 index 00000000..5e80b23c --- /dev/null +++ b/S2OJ/1812/data/divide6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea7f52097e6562bb5d8af7ac06a78b5763b8e54f7f32aa9850dc887bdcaefa92 +size 60667 diff --git a/S2OJ/1812/data/divide6.out b/S2OJ/1812/data/divide6.out new file mode 100644 index 00000000..7a8d544a --- /dev/null +++ b/S2OJ/1812/data/divide6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03b5626eeedb0b767ab723adbca2be13a51e6e882b22d3d2185d3223e40bfceb +size 7 diff --git a/S2OJ/1812/data/divide7.in b/S2OJ/1812/data/divide7.in new file mode 100644 index 00000000..91785e98 --- /dev/null +++ b/S2OJ/1812/data/divide7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76e2b001cb2776424050bcfad440df20d2d0018ff31ccdbf7a63bb705e6e005e +size 73230 diff --git a/S2OJ/1812/data/divide7.out b/S2OJ/1812/data/divide7.out new file mode 100644 index 00000000..1afef38a --- /dev/null +++ b/S2OJ/1812/data/divide7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9736fc5fe72b2acb92f87660903d0237ff484900bdff0559ca37490ef936417a +size 7 diff --git a/S2OJ/1812/data/divide8.in b/S2OJ/1812/data/divide8.in new file mode 100644 index 00000000..6879eaa3 --- /dev/null +++ b/S2OJ/1812/data/divide8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c7ef16dccd20c108138483cf13a0760093d60a0aef03c10a6ad135529ad73bf +size 98307 diff --git a/S2OJ/1812/data/divide8.out b/S2OJ/1812/data/divide8.out new file mode 100644 index 00000000..f61d999b --- /dev/null +++ b/S2OJ/1812/data/divide8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:911a1eb3f79da97bb16720319276a61fb9e07cac890cf486b3fafeb0006ca6c5 +size 7 diff --git a/S2OJ/1812/data/divide9.in b/S2OJ/1812/data/divide9.in new file mode 100644 index 00000000..1e9ce1fb --- /dev/null +++ b/S2OJ/1812/data/divide9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b90c5a6893fc8728e523220084810b575e57fbbb848a798004f5738c2e71503 +size 170428 diff --git a/S2OJ/1812/data/divide9.out b/S2OJ/1812/data/divide9.out new file mode 100644 index 00000000..2977ce2b --- /dev/null +++ b/S2OJ/1812/data/divide9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdfdcc9ec2429c317f2bdd4fc0ab658ee4f253bb8a422a615dedcbba632bcc46 +size 7 diff --git a/S2OJ/1812/data/problem.conf b/S2OJ/1812/data/problem.conf new file mode 100644 index 00000000..1c72cdab --- /dev/null +++ b/S2OJ/1812/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66b1b5459d4850b5d787a1913d75d120418acfc96e71d1aca8abc30fe31f2fe6 +size 181