1 条题解

  • 1
    @ 2025-6-22 17:08:56
    #include<bits/stdc++.h>  
    using namespace std;
    typedef long long ll;
    const int maxn = 2e5+5;
    priority_queue<int> p1;
    priority_queue<int,vector<int>,greater<int> > p2;
    int a[maxn],u[maxn],m,n;
    int main()
    {
    	cin>>n>>m;
    	for(int i=1;i<=n;i++) cin>>a[i];
    	for(int i=1;i<=m;i++)
    	{
    		cin>>u[i];
    		for(int j=u[i-1]+1;j<=u[i];j++)
    		{
    			if(p1.empty() || p1.top() >= a[j]) p1.push(a[j]);
    			else p2.push(a[j]);
    		}
    		while(p1.size() < i)
    		{
    			p1.push(p2.top());
    			p2.pop();
    		}
    		while(p1.size() > i)
    		{
    			p2.push(p1.top());
    			p1.pop();
    		}
    		cout<<p1.top()<<'\n';
    	}
    	return 0;
    } 
    
    • 1

    信息

    ID
    1534
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    13
    已通过
    5
    上传者