QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#247587#7689. Flipping Cardsucup-team1074WA 1ms9984kbC++202.2kb2023-11-11 15:01:382023-11-11 15:01:39

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 15:01:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9984kb
  • [2023-11-11 15:01:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 3e5 + 10;
typedef pair<int, int> PII;
int a[N], b[N];
PII c[N];
int idx[N], idx1[N];
int n;
bool cmp (int x, int y) {
	return c[x] < c[y];
}

bool check (int x) {
	int y = x - 1 - (n - 1) / 2;
	int cnt = 1;
	vector<int> id;
	for (int i = 1; i < x; i++) {
		if (c[idx[i]].second >= c[idx[x]].first)
			id.push_back (idx[i]);
	}
	sort (id.begin (), id.end ());
	int pos = 1;
	for (int i = 1; i < id.size (); i++) {
		if (id[i] - id[i - 1] == 1) {
			pos += 1;
			cnt = max (cnt, pos);
		}
		else pos = 1;
	}
	if (id.empty ()) cnt = 0;
	return cnt >= y;
}

bool check1 (int x) {
	int num = 0;
	for (int i = 1; i <= n; i++) {
		if (i == idx1[x]) continue;
		if (c[i].first < c[idx1[x]].second) num++;
	}
	int y = num - (n - 1) / 2;
	int cnt1 = 0, cnt2 = 0;
	int max1 = 0, max2 = 0;
	for (int i = idx1[x] - 1; i >= 1; i--) {
		if (c[i].second >= c[idx1[x]].second && c[i].first < c[idx1[x]].second)
			cnt1++;
		else if (c[i].second < c[idx1[x]].second && c[i].first >= c[idx1[x]].second)
			cnt1--;
		max1 = max (max1, cnt1);
	}
	for (int i = idx1[x] + 1; i <= n; i++) {
		if (c[i].second >= c[idx1[x]].second && c[i].first < c[idx1[x]].second)
			cnt2++;
		else if (c[i].second < c[idx1[x]].second && c[i].first >= c[idx1[x]].second)
			cnt2--;
		max2 = max (max2, cnt2);
	}
	return max1 + max2 >= y;

}

bool cmp1 (int x, int y) {
	if (c[x].second == c[y].second)
		return c[x].first < c[y].first;
	else return c[x].second < c[y].second;
}

int main () {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		c[i] = { a[i], b[i] };
		idx[i] = i;
		idx1[i] = i;
	}
	sort (idx + 1, idx + n + 1, cmp);
	sort (idx1 + 1, idx1 + n + 1, cmp1);
	// for (int i = 1; i <= n; i++) {
	// 	cout << c[idx[i]].first << " " << c[idx[i]].second << endl;
	// }

	int l = ((n + 1) / 2), r = n;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check (mid)) l = mid;
		else r = mid - 1;
	}
	int ans = c[idx[l]].first;

	l = 1, r = n;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check1 (mid)) l = mid;
		else r = mid - 1;
	}

	//cout << idx1[l] << l << endl;
	ans = max (c[idx1[l]].second, ans);
	cout << ans;

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7900kb

input:

5
3 6
5 2
4 7
6 4
2 8

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9984kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 7652kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 7592kb

input:

99
749159996 323524232
125448341 365892333
481980673 143665393
394405973 44741918
687549448 513811513
287088118 385131171
11865696 666468353
449920567 373650719
671547289 116780561
41003675 671513243
351534153 507850962
374160874 985661954
222519431 600582098
987220654 704142246
856147059 37783620
1...

output:

507850962

result:

wrong answer 1st numbers differ - expected: '528957505', found: '507850962'