蒟蒻求助QAQ
  • 板块P1168 中位数
  • 楼主Huanghy
  • 当前回复5
  • 已保存回复5
  • 发布时间2021/8/6 20:17
  • 上次更新2023/11/4 11:47:13
查看原帖
蒟蒻求助QAQ
225777
Huanghy楼主2021/8/6 20:17

rt,P1168五个点全WA

#include <bits/stdc++.h>
using namespace std;

priority_queue <int,vector<int>,greater<int> > q1;//升序 
priority_queue <int,vector<int>,less<int> >q2;//降序 

int main()
{
 int n,x,y,k,m; 
    scanf("%d",&n);
    scanf("%d",&x);
    k=x;
    printf("%d\n",x);
    for(int i=2;i<=n;i+=2)
    {
        scanf("%d%d",&x,&y);
        q1.push(max(x,y));
        q2.push(min(x,y));
        while(q1.top()<q2.top())
        {
        	int h1=q1.top(),h2=q2.top();
        	q1.pop();
        	q1.push(h2);
        	q2.pop();
        	q2.push(h1); 
		}
        while(k>q1.top())
        {
        	q1.push(k);
        	k=q1.top();
        	q1.pop();
		}
		while(q1.top()<q2.top())
        {
        	int h1=q1.top(),h2=q2.top();
        	q1.pop();
        	q1.push(h2);
        	q2.pop();
        	q2.push(h1); 
		}
		while(k<q2.top())
        {
        	q2.push(k);
        	k=q2.top();
        	q2.pop();
		}
		printf("%d\n",k);
    }
    return 0;
}
2021/8/6 20:17
加载中...