結果

問題 No.919 You Are A Project Manager
ユーザー msm1993msm1993
提出日時 2020-03-31 18:03:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 3,000 ms
コード長 3,326 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 119,192 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 03:21:30
合計ジャッジ時間 7,399 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 66 ms
4,376 KB
testcase_18 AC 65 ms
4,376 KB
testcase_19 AC 66 ms
4,380 KB
testcase_20 AC 83 ms
4,376 KB
testcase_21 AC 67 ms
4,380 KB
testcase_22 AC 38 ms
4,380 KB
testcase_23 AC 37 ms
4,380 KB
testcase_24 AC 39 ms
4,376 KB
testcase_25 AC 38 ms
4,376 KB
testcase_26 AC 81 ms
4,380 KB
testcase_27 AC 71 ms
4,380 KB
testcase_28 AC 89 ms
4,380 KB
testcase_29 AC 66 ms
4,380 KB
testcase_30 AC 66 ms
4,380 KB
testcase_31 AC 65 ms
4,380 KB
testcase_32 AC 65 ms
4,376 KB
testcase_33 AC 41 ms
4,380 KB
testcase_34 AC 41 ms
4,380 KB
testcase_35 AC 90 ms
4,380 KB
testcase_36 AC 91 ms
4,384 KB
testcase_37 AC 91 ms
4,380 KB
testcase_38 AC 91 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 4 ms
4,376 KB
testcase_44 AC 7 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 38 ms
4,380 KB
testcase_48 AC 38 ms
4,380 KB
testcase_49 AC 40 ms
4,380 KB
testcase_50 AC 38 ms
4,380 KB
testcase_51 AC 34 ms
4,380 KB
testcase_52 AC 27 ms
4,380 KB
testcase_53 AC 35 ms
4,376 KB
testcase_54 AC 5 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,380 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 cntr=mat[dep].rank(0, r), cntl=mat[dep].rank(0, l);
			if(cntl==cntr){
				l=l-cntl+zs[dep];
				r=r-cntr+zs[dep];
				ret=((ret<<1)|1);
			}else{
				l=cntl;
				r=cntr;
				ret<<=1;
			}
		}
		return ret;
	}
	T quantile(int l, int r, int k){ // return k-th largest value in [l,r)
		T ret=0;
		for(int dep=0; dep<MAXLOG; dep++){
			int cntr=mat[dep].rank(r), cntl=mat[dep].rank(l);
			if(cntr-cntl>=k){
				l=cntl+zs[dep];
				r=cntr+zs[dep];
				ret=((ret<<1)|1);
			}else{
				l=l-cntl;
				r=r-cntr;
				ret<<=1;
				k-=(cntr-cntl);
			}
		}
		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