卡常竟然卡过了!!!!!!!!!!!!
查看原帖
卡常竟然卡过了!!!!!!!!!!!!
180250
赌雾楼主2020/8/23 18:19
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 10;
int heap[maxN];
int n, m, tot = 0;
void put(int ), get(), work();
int main(){
	work();	
	return 0;
} 
void work(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int op, x;
		cin >> op;
		if(op == 1) {cin >> x; put(x);}
		else if(op == 3) get();
		else cout << heap[1] << endl;
	}
}
void put(int x){
	int son, fa;
	heap[++tot] = x;
	son = tot;
	while(son > 1){
		fa = son / 2;
//		fa = son >> 1; 位运算写法 
		if(heap[son] >= heap[fa]) break;
		swap(heap[son], heap[fa]);
		son = fa;
	}
} 
void get(){
	heap[1] = heap[tot--];
	int son, fa = 1;
	while(2 * fa <= tot){
		son = 2 * fa;
//		son = fa << 1; 位运算写法 
		if(heap[son] >= heap[son + 1] && son < tot) son++;
		if(heap[son] > heap[fa]) break;
		swap(heap[son], heap[fa]);
		fa = son;
	}
}

第一次第11个点TLE了!!!!!!!!

第二次再交就AC了!!!!!!!!!

哦!舒服……

2020/8/23 18:19
加载中...