結果

問題 No.919 You Are A Project Manager
ユーザー chocoruskchocorusk
提出日時 2019-10-30 15:10:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 3,000 ms
コード長 3,248 bytes
コンパイル時間 1,246 ms
コンパイル使用メモリ 117,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 03:34:05
合計ジャッジ時間 5,261 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 15 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 36 ms
4,380 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 20 ms
4,380 KB
testcase_17 AC 64 ms
4,380 KB
testcase_18 AC 65 ms
4,380 KB
testcase_19 AC 67 ms
4,376 KB
testcase_20 AC 86 ms
4,380 KB
testcase_21 AC 64 ms
4,376 KB
testcase_22 AC 39 ms
4,376 KB
testcase_23 AC 38 ms
4,380 KB
testcase_24 AC 40 ms
4,380 KB
testcase_25 AC 39 ms
4,380 KB
testcase_26 AC 83 ms
4,376 KB
testcase_27 AC 74 ms
4,376 KB
testcase_28 AC 92 ms
4,380 KB
testcase_29 AC 63 ms
4,376 KB
testcase_30 AC 62 ms
4,376 KB
testcase_31 AC 64 ms
4,376 KB
testcase_32 AC 64 ms
4,376 KB
testcase_33 AC 43 ms
4,380 KB
testcase_34 AC 42 ms
4,380 KB
testcase_35 AC 94 ms
4,376 KB
testcase_36 AC 94 ms
4,380 KB
testcase_37 AC 94 ms
4,376 KB
testcase_38 AC 94 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 6 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 40 ms
4,380 KB
testcase_48 AC 39 ms
4,380 KB
testcase_49 AC 42 ms
4,376 KB
testcase_50 AC 39 ms
4,380 KB
testcase_51 AC 36 ms
4,380 KB
testcase_52 AC 28 ms
4,376 KB
testcase_53 AC 36 ms
4,380 KB
testcase_54 AC 5 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct FullyIndexableDictionary{
	int len, blk;
	vector<unsigned> bit;
	vector<int> sum;
	FullyIndexableDictionary(){}
	FullyIndexableDictionary(int len):len(len), blk((len+31)>>5), bit(blk), sum(blk){}

	void set(int k){
		bit[k>>5]|=1u<<(k&31);
	}
	void build(){
		for(int i=1; i<blk; i++){
			sum[i]=sum[i-1]+__builtin_popcount(bit[i-1]);
		}
	}
	int rank(int k){
		return sum[k>>5]+__builtin_popcount(bit[k>>5]&((1u<<(k&31))-1));
	}
	int rank(bool v, int k){
		return (v ? rank(k) : k-rank(k));
	}
};
template<typename T, int MAXLOG>
struct WaveletMatrix{
	int len;
	FullyIndexableDictionary mat[MAXLOG];
	int zs[MAXLOG];

	WaveletMatrix(vector<T> data){
		len=data.size();
		vector<T> ls(len), rs(len);
		for(int dep=0; dep<MAXLOG; dep++){
			mat[dep]=FullyIndexableDictionary(len+1);
			int p=0, q=0;
			for(int i=0; i<len; i++){
				bool k=(data[i]>>(MAXLOG-(dep+1)))&1;
				if(k){
					rs[q++]=data[i];
					mat[dep].set(i);
				}else{
					ls[p++]=data[i];
				}
			}
			zs[dep]=p;
			mat[dep].build();
			swap(ls, data);
			for(int i=0; i<q; i++) data[i+p]=rs[i];
		}
	}
	int rank(T v, int l, int r){
		for(int dep=0; dep<MAXLOG; dep++){
			bool bit=(v>>(MAXLOG-(dep+1)))&1;
			l=mat[dep].rank(bit, l)+zs[dep]*bit;
			r=mat[dep].rank(bit, r)+zs[dep]*bit;
		}
		return r-l;
	}
	int rank(T v, int k){
		return rank(v, 0, k);
	}
	T rangemin(int l, int r){
		T ret=0;
		for(int dep=0; dep<MAXLOG; dep++){
			int cnt=mat[dep].rank(0, r)-mat[dep].rank(0, l);
			bool bit=(cnt==0);
			ret=((ret<<1)|bit);
			l=mat[dep].rank(bit, l)+zs[dep]*bit;
			r=mat[dep].rank(bit, r)+zs[dep]*bit;
		}
		return ret;
	}
	T quantile(int l, int r, int k){
		T ret=0;
		for(int dep=0; dep<MAXLOG; dep++){
			int cnt=mat[dep].rank(r)-mat[dep].rank(l);
			bool bit=(cnt>=k);
			ret=((ret<<1)|bit);
			l=mat[dep].rank(bit, l)+zs[dep]*bit;
			r=mat[dep].rank(bit, r)+zs[dep]*bit;
			if(!bit) k-=cnt;
		}
		return ret;
	}
};
int main()
{
	int n;
    cin>>n;
	vector<int> a(n);
	const int MAX=1e9;
    for(int i=0; i<n; i++){
		cin>>a[i];
		a[i]+=MAX;
	}
	WaveletMatrix<int, 31> wm(a);
	auto med=[&](int l, int r){
		if(r-l==1) return a[l]-MAX;
		else if(r-l==2) return min(a[l], a[l+1])-MAX;
		else return wm.quantile(l, r, (r-l)/2+1)-MAX;
	};
    ll ans=0;
    for(int k=1; k<=n; k++){
        vector<ll> sl(n/k+1), sr(n/k+1);
        for(int j=0; j<n/k; j++){
            sl[j+1]=sl[j]+med(j*k, (j+1)*k);
        }
        for(int j=0; j<n/k; j++){
            sr[j+1]=sr[j]+med(n-(j+1)*k, n-j*k);
        }
        ll mx=0;
        ans=max(ans, sr[n/k]*k);
        for(int j=1; j<=n/k; j++){
            mx=max(mx, sl[j]);
            ans=max(ans, (mx+sr[n/k-j])*k);        
        }
    }
    cout<<ans<<endl;
	return 0;
}
0