对顶堆求调,第八个点WA了
查看原帖
对顶堆求调,第八个点WA了
917522
zhang10086楼主2024/2/26 23:20
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N = 2e5 + 10;

int n, m;
int arr[N], u[N];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> m >> n;
	for (int i = 1; i <= m; i++)
		cin >> arr[i];

	for (int i = 1; i <= n; i++) {
		cin >> u[i];
	}
	priority_queue<int>a;//大根堆
	priority_queue<int, vector<int>, greater<int>>b;//小根堆
	int j = 0;
	int k = 1;
	for (int i = 1; i <= n; i++) {
		j++;
		while (k <= u[i]) {
			for (; k <= u[i]; k++) {
				if (b.empty() || arr[k] >= b.top())
					b.push(arr[k]);
				else
					a.push(arr[k]);
				while (a.size() > j)b.push(a.top()), a.pop();
				while (a.size() < j)a.push(b.top()), b.pop();
			}
		}
		while (a.size() > j)b.push(a.top()), a.pop();
		while (a.size() < j)a.push(b.top()), b.pop();
		
		cout << a.top() << '\n';
	}


	return 0;
}
2024/2/26 23:20
加载中...