結果

問題 No.919 You Are A Project Manager
ユーザー kotatsugamekotatsugame
提出日時 2019-10-25 23:57:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,012 ms / 3,000 ms
コード長 1,573 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 84,628 KB
実行使用メモリ 7,088 KB
最終ジャッジ日時 2023-09-10 01:31:00
合計ジャッジ時間 25,745 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 861 ms
6,892 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 144 ms
4,376 KB
testcase_05 AC 158 ms
4,376 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 343 ms
4,664 KB
testcase_08 AC 67 ms
4,376 KB
testcase_09 AC 46 ms
4,376 KB
testcase_10 AC 88 ms
4,380 KB
testcase_11 AC 83 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 113 ms
4,380 KB
testcase_14 AC 5 ms
4,384 KB
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 171 ms
4,388 KB
testcase_17 AC 868 ms
7,008 KB
testcase_18 AC 842 ms
7,072 KB
testcase_19 AC 874 ms
7,020 KB
testcase_20 AC 916 ms
6,908 KB
testcase_21 AC 867 ms
6,892 KB
testcase_22 AC 379 ms
4,984 KB
testcase_23 AC 366 ms
4,964 KB
testcase_24 AC 391 ms
4,960 KB
testcase_25 AC 375 ms
4,920 KB
testcase_26 AC 894 ms
6,768 KB
testcase_27 AC 752 ms
5,600 KB
testcase_28 AC 994 ms
6,924 KB
testcase_29 AC 870 ms
7,088 KB
testcase_30 AC 870 ms
7,088 KB
testcase_31 AC 872 ms
6,936 KB
testcase_32 AC 870 ms
6,952 KB
testcase_33 AC 413 ms
4,992 KB
testcase_34 AC 416 ms
4,944 KB
testcase_35 AC 1,012 ms
6,940 KB
testcase_36 AC 1,005 ms
6,948 KB
testcase_37 AC 1,009 ms
6,892 KB
testcase_38 AC 1,011 ms
7,088 KB
testcase_39 AC 3 ms
4,384 KB
testcase_40 AC 30 ms
4,380 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 9 ms
4,376 KB
testcase_43 AC 16 ms
4,376 KB
testcase_44 AC 41 ms
4,376 KB
testcase_45 AC 9 ms
4,380 KB
testcase_46 AC 33 ms
4,376 KB
testcase_47 AC 371 ms
5,136 KB
testcase_48 AC 368 ms
4,916 KB
testcase_49 AC 393 ms
4,804 KB
testcase_50 AC 374 ms
4,860 KB
testcase_51 AC 338 ms
4,728 KB
testcase_52 AC 253 ms
4,380 KB
testcase_53 AC 339 ms
4,660 KB
testcase_54 AC 30 ms
4,384 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:47:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   47 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#include<vector>
#include<algorithm>
template<typename T>
struct rangefreq{
	int n;
	vector<vector<T> >dat;
	rangefreq(const vector<T>&v={})
	{
		n=1;
		while(n<v.size())n<<=1;
		dat.assign(2*n-1,{});
		for(int i=0;i<v.size();i++)dat[i+n-1].push_back(v[i]);
		for(int i=n-2;i>=0;i--)
		{
			dat[i].resize(dat[i*2+1].size()+dat[i*2+2].size());
			merge(dat[i*2+1].begin(),dat[i*2+1].end(),
				dat[i*2+2].begin(),dat[i*2+2].end(),
				dat[i].begin()
			);
		}
	}
	int query(int a,int b,T x,int k=0,int l=0,int r=-1)const//[a,b) count(*<x)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return 0;
		else if(a<=l&&r<=b)return lower_bound(dat[k].begin(),dat[k].end(),x)-dat[k].begin();
		else return query(a,b,x,k*2+1,l,(l+r)/2)+query(a,b,x,k*2+2,(l+r)/2,r);
	}
};
int N;
int f(int L,int R,const rangefreq<int>&P)
{
	long l=-1e9,r=1e9+1;
	int K=R-L;
	while(r-l>1)
	{
		long m=(l+r)/2;
		if(P.query(L,R,m)>=(K+1)/2)r=m;
		else l=m;
	}
	return l;
}
main()
{
	cin>>N;
	vector<int>A(N);
	for(int&a:A)cin>>a;
	rangefreq<int>P(A);
	reverse(A.begin(),A.end());
	rangefreq<int>Q(A);
	long ans=0;
	for(int K=1;K<=N;K++)
	{
		int t=(K-1)/2;
		vector<long>L(N/K),R(N/K);
		for(int i=0;i+K<=N;i+=K)
		{
			L[i/K]=f(i,i+K,P);
			R[i/K]=f(i,i+K,Q);
		}
		for(int i=1;i<N/K;i++)
		{
			L[i]+=L[i-1];
			R[i]+=R[i-1];
		}
		for(int i=1;i<N/K;i++)
		{
			L[i]=max(L[i],L[i-1]);
			R[i]=max(R[i],R[i-1]);
		}
		for(int i=-1;i<N/K;i++)
		{
			int j=N/K-i-2;
			ans=max(ans,((i<0?0L:L[i])+(j<0?0L:R[j]))*K);
		}
	}
	cout<<ans<<endl;
}
0