結果

問題 No.2735 Demarcation
ユーザー startcppstartcpp
提出日時 2024-04-19 23:21:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,574 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 43,860 KB
最終ジャッジ日時 2024-04-19 23:21:50
合計ジャッジ時間 9,306 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 AC 235 ms
8,576 KB
testcase_22 AC 303 ms
10,880 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <bitset>
#include <atcoder/segtree>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
using namespace atcoder;

const int INF = (1LL << 60) + 1;
int op(int a, int b) {
	if (a > INF / b) return INF;
	return a * b;
}
int e() { return 1; }

int n, q;
vector<int> X, ls, rs, s;

void input() {
	int i;
	cin >> n;
	X.resize(n);
	rep(i, n) cin >> X[i];
	cin >> q;
	ls.resize(q);
	rs.resize(q);
	s.resize(q);
	rep(i, q) {
		cin >> ls[i] >> rs[i] >> s[i];
		ls[i]--;
	}
}

int solve_dp(vector<int> &X, int l, int r, int s) {
	int i, j, n = r - l;
	vector<int> a(n), sa(n);
	rep(i, n) { a[i] = X[l + i]; sa[i] = a[i]; }
	sort(sa.begin(), sa.end());
	sa.erase(unique(sa.begin(), sa.end()));
	rep(i, n) { a[i] = lower_bound(sa.begin(), sa.end(), a[i]) - sa.begin(); }

	int ok = 0, ng = n + 1, mid;
	bool kusira = false;
	while (ng - ok >= 2) {
		mid = (ok + ng) / 2;
		vector<int> dp(n + 1);
		dp[0] = 1;
		rep(i, n) {
			bitset<90> bs; int cnt = 0;
			for (j = i + 1; j <= n; j++) {
				if (!bs[a[j - 1]]) { bs[a[j - 1]] = 1; cnt++; }
				if (cnt > mid) { break; }
				dp[j] += dp[i];
				if (dp[j] > s) { kusira = true; break; }
			}
			if (kusira) break;
		}
		if (kusira) ng = mid;
		else ok = mid;
	}
	if (ok >= n) return -1;
	return ok;
}

vector<int> poses, cnts;

void shokorassyo(int midori_coder_tuyoi = 90) {
	poses.push_back(0);
	for (int i = 1; i < n; i++) {
		if (X[i - 1] != X[i]) {
			poses.push_back(i);
		}
	}
	poses.push_back(n);

	for (int i = 0; i < (int)poses.size() - 1; i++) {
		int interval = poses[i + 1] - poses[i];
		int val = (interval > 61) ? INF : (1LL << (interval - 1));
		cnts.push_back(val);
	}

	segtree<int, op, e> seg(cnts);
	vector<int> ans(q);
	for (int i = 0; i < q; i++) {
		if (rs[i] - ls[i] < midori_coder_tuyoi) {
			cout << solve_dp(X, ls[i], rs[i], s[i]) << endl;
		}
		else {
			int it1 = lower_bound(poses.begin(), poses.end(), ls[i]) - poses.begin();
			int it2 = upper_bound(poses.begin(), poses.end(), rs[i]) - poses.begin(); it2--;
			int pro = seg.prod(it1, it2);
			int inter1 = poses[it1] - ls[i]; int val1 = (inter1 > 61) ? INF : (1LL << max(inter1 - 1, 0LL));
			int inter2 = rs[i] - poses[it2]; int val2 = (inter2 > 61) ? INF : (1LL << max(inter2 - 1, 0LL));
			if (val1 <= s[i] / pro) pro *= val1; else pro = INF;
			if (val2 <= s[i] / pro) pro *= val2; else pro = INF;
			if (pro < s[i]) cout << 2 << endl;
			else if (pro == s[i]) cout << 1 << endl;
			else cout << 0 << endl;
		}
	}
}

signed main() {
	input();
	shokorassyo();
	return 0;
}
0