結果

問題 No.919 You Are A Project Manager
ユーザー ningenMeningenMe
提出日時 2019-09-12 23:19:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,399 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 188,856 KB
実行使用メモリ 16,836 KB
最終ジャッジ日時 2023-09-15 14:24:30
合計ジャッジ時間 7,713 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 24 ms
5,424 KB
testcase_05 AC 27 ms
5,704 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 3 ms
4,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <class T> void chmax(T& a, const T b){a=max(a,b);}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}

inline void balance(multiset<long long>& stl,multiset<long long>& str) {
	while(stl.size()>str.size()+1) {
		long long tmp = *stl.rbegin();
		str.insert(tmp);
		stl.erase(stl.find(tmp));
	}
	while(stl.size()<str.size()) {
		stl.insert(*str.begin());
		str.erase(str.begin());
	}
}
inline void balanceLtoR(multiset<long long>& stl,multiset<long long>& str) {
	while(stl.size()>str.size()+1) {
		long long tmp = *stl.rbegin();
		str.insert(tmp);
		stl.erase(stl.find(tmp));
	}
}

inline void balanceRtoL(multiset<long long>& stl,multiset<long long>& str) {
	if(stl.size()<str.size()) {
		stl.insert(*str.begin());
		str.erase(str.begin());
	}
}


inline void exchange(multiset<long long>& stl,multiset<long long>& str){
	long long tmpl = *stl.rbegin();
	long long tmpr = *str.begin();
	if(tmpl>tmpr) {
		stl.erase(stl.find(tmpl));
		stl.insert(tmpr);
		str.erase(str.find(tmpr));
		str.insert(tmpl);
	}
}

int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<long long> A(N);
	for(int i = 0; i < N; ++i) cin >> A[i];

	//クエリ区間を列挙、調和級数なのでO(NlogN)
	vector<pair<long long,long long>> range;
	for(int i = 1; i <= N; ++i) {
		for(int j = 0; j+i <= N; j+=i) range.push_back({j,j+i-1});
		for(int j = N; 0 <= j-i; j-=i) range.push_back({j-i,j-1});
	}
	
	//Mo順ソート O(NlogNlog(NlogN))
	int bucket = sqrt(N);
	vector<int> idx(range.size());
	iota(idx.begin(),idx.end(),0);
	sort(idx.begin(),idx.end(),[&](int a, int b){
		auto& al = range[a].first;
		auto& ar = range[a].second;
		auto& bl = range[b].first;
		auto& br = range[b].second;
		return (al/bucket != bl/bucket) ? (al/bucket < bl/bucket) : (ar < br);
	});


	//Moで中央値列挙 O(Nsqrt(N)(logN)^2)
	int l = 0, r = 0;
	multiset<long long> stl,str;
	stl.insert(A[0]);
	unordered_map<long long,long long> mp;

	// for(int& i:idx){
	// 	auto& xl = range[i].first;
	// 	auto& xr = range[i].second;
		
	// 	//左端を狭める
	// 	while(l < xl){
	// 		if(stl.count(A[l])) {
	// 			stl.erase(stl.find(A[l]));
	// 			balanceRtoL(stl,str);
	// 		}
	// 		else {
	// 			str.erase(str.find(A[l]));
	// 			balanceLtoR(stl,str);
	// 		}
	// 		l++;
	// 	}
	// 	//左端を広げる
	// 	while(xl < l){
	// 		l--;
	// 		stl.insert(A[l]);
	// 		if(str.size()) exchange(stl,str);
	// 		balanceLtoR(stl,str);
	// 	}
	// 	//右端を広げる
	// 	while(r < xr){
	// 		r++;
	// 		stl.insert(A[r]);
	// 		if(str.size()) exchange(stl,str);
	// 		balanceLtoR(stl,str);
	// 	}
	// 	//左端を広げる
	// 	while(xr < r){
	// 		if(stl.count(A[r])) {
	// 			stl.erase(stl.find(A[r]));
	// 			balanceRtoL(stl,str);
	// 		}
	// 		else {
	// 			str.erase(str.find(A[r]));
	// 			balanceLtoR(stl,str);
	// 		}
	// 		r--;
	// 	}
	// 	mp[xl*N+xr] = *stl.rbegin();
	// }

	long long ans = 0;
	int cnt = 0;
	for(long long i = 1; i <= N; ++i) {
		int M = N/i;
		vector<long long> lSum(M,0),rSum(M,0);
		vector<pair<long long,long long>> lRange(M),rRange(M);
		//区間取得
		for(int j = 0;    j < M; ++j) lRange[j] = range[cnt+j];
		for(int j = M-1; 0 <= j; --j) rRange[j] = range[cnt + 2*M-1 - j];
		//中央値取得
		for(int j = 0;    j < M; ++j) lSum[j]   = i*mp[lRange[j].first*N+lRange[j].second];
		for(int j = M-1; 0 <= j; --j) rSum[j]   = i*mp[rRange[j].first*N+rRange[j].second];
		//累積和
		for(int j = 1;    j < M; ++j) lSum[j]  += lSum[j-1];
		for(int j = M-2; 0 <= j; --j) rSum[j]  += rSum[j+1];
		//累積max
		for(int j = 1;    j < M; ++j) chmax(lSum[j],lSum[j-1]);
		for(int j = M-2; 0 <= j; --j) chmax(rSum[j],rSum[j+1]);

		chmax(ans,lSum[M-1]);
		chmax(ans,rSum[0]);

		//尺取りしながら左右決め打ち全探索
		int k = 0;
		for(int j = 0; j < M; ++j) {
			while(k < M && range[cnt + j].second >= range[cnt + 2*M-1-k].first) k++;
			if(k<M && lRange[j].second < rRange[k].first) {
				chmax(ans,lSum[j]+rSum[k]);
			}
		}
		cnt += 2*M;
	}
	cout << ans << endl;
    return 0;
}
0