結果

問題 No.919 You Are A Project Manager
ユーザー kroton
提出日時 2019-10-25 22:26:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,650 ms / 3,000 ms
コード長 3,014 bytes
コンパイル時間 1,815 ms
コンパイル使用メモリ 107,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 17:13:09
合計ジャッジ時間 31,637 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */
const int B = 500;
const ll INF = 1ll << 60;
template <class T>
vector<T> sumup(const vector<T>& a) {
int N = a.size();
vector<T> res(N + 1);
for (int i = 0; i < N; i++) res[i + 1] = res[i] + a[i];
return res;
}
int main() {
#ifdef DEBUG
ifstream ifs("in.txt");
cin.rdbuf(ifs.rdbuf());
#endif
int N;
while (cin >> N) {
vector<int> A(N);
for (int& x : A) cin >> x;
vec<int, 2> bucket((N + B - 1) / B);
vector<int> nums = A;
for (int i = 0; i < N; i++) {
bucket[i / B].push_back(A[i]);
}
sort(nums.begin(), nums.end());
for (int i = 0; i < N / B; i++) sort(bucket[i].begin(), bucket[i].end());
auto query = [&](int l, int r, int k) {
int lb = -1, ub = N - 1;
while (ub - lb > 1) {
int md = (lb + ub) / 2;
int x = nums[md];
int tl = l, tr = r, c = 0;
while (tl < tr && tl % B != 0)
if (A[tl++] <= x) c++;
while (tl < tr && tr % B != 0)
if (A[--tr] <= x) c++;
while (tl < tr) {
int b = tl / B;
c += upper_bound(bucket[b].begin(), bucket[b].end(), x) - bucket[b].begin();
tl += B;
}
if (c >= k)
ub = md;
else
lb = md;
}
return nums[ub];
};
ll res = 0;
for (int K = 1; K <= N; K++) {
vector<ll> L(N / K), R(N / K);
for (int l = 0, i = 0; l + K <= N; l += K, i++) L[i] = query(l, l + K, (K + 1) / 2);
for (int r = N, i = 0; r - K >= 0; r -= K, i++) R[i] = query(r - K, r, (K + 1) / 2);
auto sumL = sumup(L);
auto sumR = sumup(R);
auto maxL = sumL;
for (int i = 1; i < maxL.size(); i++) maxL[i] = max(maxL[i - 1], maxL[i]);
auto maxR = sumR;
for (int i = 1; i < maxR.size(); i++) maxR[i] = max(maxR[i - 1], maxR[i]);
for (int l = 0; l <= N / K; l++) {
chmax(res, K * (maxL[l] + maxR[N / K - l]));
}
}
cout << res << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0