mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:11:58 +00:00
#1812. 【2017.3 长乐省选集训 Day10 T2】划分序列
https://sjzezoj.com/submission/66456
This commit is contained in:
parent
da50312cc6
commit
dda9cfdeb7
127
S2OJ/1812/1812.cpp
Normal file
127
S2OJ/1812/1812.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 5e4 + 5;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
|
||||
template <typename T>
|
||||
struct Max {
|
||||
T operator()(T a, T b) const {
|
||||
return std::max(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Min {
|
||||
T operator()(T a, T b) const {
|
||||
return std::min(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, int N, class Operator = std::plus<int>>
|
||||
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<int> nums;
|
||||
BIT<int, N << 1, Max<int>> bit_max(-INF);
|
||||
BIT<int, N << 1, Min<int>> 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<int>(), 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;
|
||||
}
|
BIN
S2OJ/1812/data/divide1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide11.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide12.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide13.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide14.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide15.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide16.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide17.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide18.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide19.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide20.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/divide9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/divide9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1812/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1812/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user