WA了一个点,九十分,求助
查看原帖
WA了一个点,九十分,求助
316486
19ty53楼主2021/8/14 15:22

错误数据

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#define int long long
using namespace std;
int n,m;
priority_queue<int>maxn,minn;
inline void read(int&x){
	x=0;static char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch-48),ch=getchar();
}
string s; 
signed main(){
	register int x,lenmax,lenmin,len;
	read(n);
	read(x);
	minn.push(-x);
	for(register int i=2;i<=n;++i){
		read(x);
		if(x>=-minn.top())minn.push(-x);
		else maxn.push(x);
		lenmax=maxn.size();
		lenmin=minn.size();
		if(lenmin-lenmax==2)maxn.push(-minn.top()),minn.pop();
		else if(lenmax-lenmin==2)minn.push(-maxn.top()),maxn.pop();
	}
	read(m);
	for(register int i=1;i<=m;++i){
		cin>>s;
		if(s=="add"){
			read(x);
			if(x>=-minn.top())minn.push(-x);
			else maxn.push(x);
			lenmax=maxn.size();
			lenmin=minn.size();
			if(lenmin-lenmax==2)maxn.push(-minn.top()),minn.pop();
			else if(lenmax-lenmin==2)minn.push(-maxn.top()),maxn.pop();
		}else{
			if(minn.size()>maxn.size())printf("%d\n",-minn.top());
			else printf("%d\n",maxn.top());
		}
	}
}
2021/8/14 15:22
加载中...