priority_queue判断当前这个知识点最便宜的练习册的编号与价值
用used数组判断是否用过
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5+10;
#define read(n) scanf("%d",&n)
int n,m;
int p[N],a[N],b[N];
bool used[N];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> t1,t2,t3;
signed main()
{
read(n);
for (int i = 1; i <= n; i ++ ) read(p[i]);
for (int i = 1; i <= n; i ++ ) read(a[i]);
for (int i = 1; i <= n; i ++ ) read(b[i]);
for (int i = 1; i <= n; i ++ )
{
if(a[i]==1) t1.push({p[i],i});
if(a[i]==2) t2.push({p[i],i});
if(a[i]==3) t3.push({p[i],i});
if(b[i]==1) t1.push({p[i],i});
if(b[i]==2) t2.push({p[i],i});
if(b[i]==3) t3.push({p[i],i});
}
read(m);
while(m--)
{
int t;
read(t);
while(t1.size()>=1&&used[t1.top().second]) t1.pop();
while(t2.size()>=1&&used[t2.top().second]) t2.pop();
while(t3.size()>=1&&used[t3.top().second]) t3.pop();
if(t==1)
{
if(t1.size()>=1)
{
cout<<t1.top().first;
used[t1.top().second]=1;
t1.pop();
}
else cout<<-1;
}
while(t1.size()>=1&&used[t1.top().second]) t1.pop();
while(t2.size()>=1&&used[t2.top().second]) t2.pop();
while(t3.size()>=1&&used[t3.top().second]) t3.pop();
if(t==2)
{
if(t2.size()>=1)
{
cout<<t2.top().first;
used[t2.top().second]=1;
t2.pop();
}
else cout<<-1;
}
while(t1.size()>=1&&used[t1.top().second]) t1.pop();
while(t2.size()>=1&&used[t2.top().second]) t2.pop();
while(t3.size()>=1&&used[t3.top().second]) t3.pop();
if(t==3)
{
if(t3.size()>=1)
{
cout<<t3.top().first;
used[t3.top().second]=1;
t3.pop();
}
else cout<<-1;
}
cout<<' ';
}
return 0;
}
lz的used数组用的好哇,我开个map都1e7了
lz啥意思?
hh楼主的缩写