QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#247580#7689. Flipping Cardsucup-team1074Compile Error//C++202.2kb2023-11-11 14:59:362023-11-11 14:59:37

Judging History

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

  • [2023-11-11 14:59:37]
  • 评测
  • [2023-11-11 14:59:36]
  • 提交

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

answer.code:1:10: fatal error: bits\stdc++.h: No such file or directory
    1 | #include <bits\stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.