求助!
  • 板块P1168 中位数
  • 楼主ZeroPrince
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/10/20 11:05
  • 上次更新2024/10/20 12:38:07
查看原帖
求助!
852876
ZeroPrince楼主2024/10/20 11:05
#include <bits/stdc++.h>
using namespace std;
#define ll long long
priority_queue<ll> bg;
priority_queue<ll, vector<ll>, greater<ll> > sm;
ll n, x;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> x;
	cout << x;
	sm.push(x);
	for (int i = 2; i <= n; i++)
	{
		cin >> x;
		if (x < sm.top()) bg.push(x);
		else sm.push(x);
		while (abs(sm.size() - bg.size()) > 1)
		{
			if (sm.size() < bg.size())
			{
				sm.push(bg.top());
				bg.pop();
			}
			else
			{
				bg.push(sm.top());
				sm.pop();
			}
		}
		if (i & 1)
		{
			cout << endl;
			if (bg.size() > sm.size()) cout << bg.top();
			else cout << sm.top();
		}
	}
	return 0;
}

在Dev上正常运行,编译命令:-Wall -O2 -std=c++14,没有警告没有报错,但在洛谷上就CE了,求助!

2024/10/20 11:05
加载中...