結果

問題 No.919 You Are A Project Manager
ユーザー kwm_tkwm_t
提出日時 2023-05-16 23:11:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,209 ms / 3,000 ms
コード長 4,069 bytes
コンパイル時間 3,092 ms
コンパイル使用メモリ 223,508 KB
実行使用メモリ 17,456 KB
最終ジャッジ日時 2023-08-21 10:22:04
合計ジャッジ時間 29,658 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,189 ms
16,364 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 124 ms
6,188 KB
testcase_05 AC 140 ms
6,304 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 269 ms
8,520 KB
testcase_08 AC 41 ms
4,660 KB
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 56 ms
4,924 KB
testcase_11 AC 52 ms
4,812 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 69 ms
5,044 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 115 ms
6,048 KB
testcase_17 AC 1,117 ms
17,376 KB
testcase_18 AC 1,118 ms
16,840 KB
testcase_19 AC 1,209 ms
16,392 KB
testcase_20 AC 895 ms
15,788 KB
testcase_21 AC 1,179 ms
16,364 KB
testcase_22 AC 300 ms
9,112 KB
testcase_23 AC 288 ms
8,624 KB
testcase_24 AC 323 ms
9,308 KB
testcase_25 AC 298 ms
8,888 KB
testcase_26 AC 841 ms
14,836 KB
testcase_27 AC 719 ms
13,932 KB
testcase_28 AC 982 ms
15,900 KB
testcase_29 AC 1,145 ms
17,456 KB
testcase_30 AC 1,120 ms
16,944 KB
testcase_31 AC 1,125 ms
17,436 KB
testcase_32 AC 1,116 ms
17,412 KB
testcase_33 AC 330 ms
9,080 KB
testcase_34 AC 331 ms
9,160 KB
testcase_35 AC 1,004 ms
16,380 KB
testcase_36 AC 1,008 ms
16,388 KB
testcase_37 AC 1,005 ms
16,316 KB
testcase_38 AC 1,004 ms
16,408 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 16 ms
4,380 KB
testcase_41 AC 4 ms
4,376 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 8 ms
4,376 KB
testcase_44 AC 24 ms
4,380 KB
testcase_45 AC 5 ms
4,380 KB
testcase_46 AC 19 ms
4,380 KB
testcase_47 AC 298 ms
8,836 KB
testcase_48 AC 290 ms
8,828 KB
testcase_49 AC 318 ms
9,096 KB
testcase_50 AC 303 ms
9,044 KB
testcase_51 AC 270 ms
8,620 KB
testcase_52 AC 188 ms
7,276 KB
testcase_53 AC 270 ms
8,408 KB
testcase_54 AC 17 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct Mo {
	int width;
	vector<int>left, right, order;
	vector<int>ans;
	//vector<long long>horder;
	int n, q;
	Mo(int _n, int _q) :n(_n), q(_q) {
		width = (int)sqrt(_n);
		order.resize(q);
		iota(all(order), 0);
		ans.resize(q);
	}
	// add,query[l,r)
	void query(vector<int> &l, vector<int> &r) {
		swap(left, l);
		swap(right, r);
		//horder.resize(q);
		//rep(i, q) horder[i] = hilbertorder(left[i], right[i]);
	}
	// run
	void run(const vector<int>&data) {
		sort(all(order), [&](int lh, int rh) {
			//return horder[lh] < horder[rh];
			int lblock = left[lh] / width;
			int rblock = left[rh] / width;
			if (lblock != rblock)return lblock < rblock;
			if (lblock & 1) return right[lh] < right[rh];
			return right[lh] > right[rh];
			});
		int nl = 0, nr = 0;
		multiset<int> x, y;
		auto add = [&](int idx) {
			x.insert(data[idx]);
			y.insert(*x.rbegin());
			x.erase(x.find(*x.rbegin()));
			x.insert(*y.begin());
			y.erase(y.begin());
			if (x.size() > y.size() + 1) {
				y.insert(*x.rbegin());
				x.erase(x.find(*x.rbegin()));
			}
		};
		auto del = [&](int idx) {
			if (x.count(data[idx])) {
				x.erase(x.find(data[idx]));
				if (x.size() < y.size()) {
					x.insert(*y.begin());
					y.erase(y.begin());
				}
			}
			else {
				y.erase(y.find(data[idx]));
				if (x.size() > y.size() + 1) {
					y.insert(*x.rbegin());
					x.erase(x.find(*x.rbegin()));
				}
			}
		};
		auto ansset = [&](int idx) {
			ans[idx] = *x.rbegin();
		};
		for (auto idx : order) {
			while (nl > left[idx])add(--nl);
			while (nr < right[idx])add(nr++);
			while (nl < left[idx])del(nl++);
			while (nr > right[idx])del(--nr);
			ansset(idx);
		}
	}
	// TLEするときはこっちを使うと通るかも
	/*const int logn = 20;
	const int maxn = 1 << logn;
	long long hilbertorder(int x, int y) {
		long long d = 0;
		for (int s = 1 << logn - 1; s; s >>= 1) {
			bool rx = x & s, ry = y & s;
			d = d << 2 | rx * 3 ^ static_cast<int>(ry);
			if (ry) continue;
			if (rx) {
				x = maxn - x;
				y = maxn - y;
			}
			swap(x, y);
		}
		return d;
	}*/
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	long long ans = 0;
	map<P, int>mp;
	vector<int>l, r;
	rep2(i, 1, n + 1) {
		for (int j = 0; j + i <= n; j += i) {
			l.push_back(j);
			r.push_back(j + i);
			mp[{j, j + i}] = mp.size();
		}
		if (0 == n % i)continue;
		for (int j = n; j - i >= 0; j -= i) {
			l.push_back(j - i);
			r.push_back(j);
			mp[{j - i, j}] = mp.size();
		}
	}
	Mo mo(n, mp.size());
	mo.query(l, r);
	mo.run(a);
	rep2(i, 1, n + 1) {
		vector<int>l, r;
		for (int j = 0; j + i <= n; j += i) {
			int idx = mp[{j, j + i}];
			l.push_back(mo.ans[idx]);
		}
		for (int j = n; j - i >= 0; j -= i) {
			int idx = mp[{j - i, j}];
			r.push_back(mo.ans[idx]);
		}
		vector<long long>sl(l.size() + 1), sr(r.size() + 1);
		rep(j, l.size())sl[j + 1] = sl[j] + l[j];
		rep(j, l.size())chmax(sl[j + 1], sl[j]);
		rep(j, r.size())sr[j + 1] = sr[j] + r[j];
		rep(j, r.size())chmax(sr[j + 1], sr[j]);
		int mx = n / i;
		rep(j, mx + 1) {
			long long sub = 0;
			sub += sl[j] - sl[0];
			int k = mx - j;
			sub += sr[k] - sr[0];
			chmax(ans, sub * i);
		}
	}
	cout << ans << endl;
	return 0;
}
0