QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65695#4835. ModeYaoBIGWA 3ms3524kbC++173.4kb2022-12-03 00:40:122022-12-03 00:40:13

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 00:40:13]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3524kb
  • [2022-12-03 00:40:12]
  • Submitted

answer

#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;

template<class A, class B> string to_string(const pair<A, B> &p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string) s); }
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(bool x) { return x ? "true" : "false"; }
template<class A> string to_string(const A &v) {
	bool first = 1;
	string res = "{";
	for (const auto &x: v) {
		if (!first) res += ", ";
		first = 0;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template<class A, class B> string to_string(const pair<A, B> &p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void debug_out() { cerr << endl; }
template<class H, class... T> void debug_out(const H& h, const T&... t) {
	cerr << " " << to_string(h);
	debug_out(t...);
}
#ifndef ONLINE_JUDGE
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
	#define debug(...) if(0) puts("No effect.")
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int cas; cin >> cas; while (cas--) {
		int n; cin >> n;
		vi as(n);
		for (auto &x: as) cin >> x;
		vi nums = as;
		sort(all(nums)); nums.erase(unique(all(nums)), nums.end());
		for (auto &x: as) x = lower_bound(all(nums), x) - nums.begin();
		int tot = sz(nums);
		vi cnt(tot);
		for (auto x: as) cnt[x]++;
		vi ans = cnt;
		
		int thr = sqrt(n) + 0.5;
		rep(occ, 1, thr) {
			vi ocnt = cnt, icnt(tot);
			vi times(n + 1);
			times[0] = tot;
			int mx = 0;
			auto add = [&](int x) {
				times[icnt[x]]--;
				icnt[x]++;
				ocnt[x]--;
				times[icnt[x]]++;
				chmax(mx, icnt[x]);
			};
			auto remove = [&](int x) {
				times[icnt[x]]--;
				icnt[x]--;
				ocnt[x]++;
				times[icnt[x]]++;
				if (times[mx] == 0) mx--;
			};
			int ptr = 0;
			auto seq_add = [&]() {
				while (ptr < n && mx != occ) {
					add(as[ptr]);
					ptr++;
				}
			};
			seq_add();
			if (mx != occ) continue;
			rep(i, 0, tot - 1) chmax(ans[i], ocnt[i] + occ);
			rep(i, 0, n - 1) {
				int x = as[i];
				remove(x);
				seq_add();
				if (mx != occ) break;
				chmax(ans[x], ocnt[x] + occ);
			}
		}
		
		vvi pls(tot);
		rep(i, 0, n - 1) {
			int x = as[i];
			pls[x].push_back(i);
		}

		rep(x, 0, tot - 1) if (sz(pls[x]) > thr) {
			vi pres(n + 1);
			for (auto p: pls[x]) pres[p] = 1;
			rep(i, 0, sz(pres) - 2) pres[i + 1] += pres[i];
			rep(y, 0, tot - 1) if (y != x) {
				int mnpre = 0;
				int mx = 0;
				rep(ind, 0, sz(pls[y]) - 1) {
					int i = pls[y][ind];
					int cur = pres[i] - ind;
					chmax(mx, cur - mnpre + sz(pls[y]));
					chmin(mnpre, pres[i + 1] - (ind + 1));
				}
				chmax(ans[y], mx);
			}
		}

		int maxans = *max_element(all(ans));
		printf("%d\n", maxans);
		rep(i, 0, sz(ans) - 1) {
			int val = nums[i];
			if (ans[i] == maxans) printf("%d\n", val);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3412kb

input:

4
5
1 2 3 2 1
5
1 1 3 1 1
6
2 4 2 4 8 8
5
1 2 3 4 5

output:

4
1
5
1
4
2
4
8
2
1
2
3
4
5

result:

ok 14 numbers

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3524kb

input:

10
300
336470888 634074578 642802746 167959139 642802746 481199252 481199252 481199252 167959139 634074578 634074578 336470888 336470888 481199252 642802746 481199252 481199252 167959139 642802746 634074578 167959139 336470888 634074578 642802746 167959139 481199252 167959139 167959139 167959139 481...

output:

80
481199252
634074578
45
153774342
574792832
39
846318354
30
937534594
27
698063951
27
419330425
20
603780410
706588687
801036056
20
541308492
19
352404708
16
187061768
428773075

result:

wrong answer 4th numbers differ - expected: '46', found: '45'