题目大意是:p为衣服价值,a为衣服前面的颜色,b为衣服后面的颜色,m是买的人有多少个。c是这些人喜欢的颜色。
如果这些人能在剩下的衣服中找到自己想要的颜色的衣服就买下来 当然是买当前最便宜的嘛。
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0);
#define rand() srand(time(0));
typedef long long LL;
typedef pair<int, int> pii;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=2e5+100;
const double EPS=1e-9;
const int MOD=1000000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;
/*lch[root] = build(L1,p-1,L2+1,L2+cnt);
rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*/
/*lch[root] = build(L1,p-1,L2,L2+cnt-1);
rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/
long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}
inline int Scan()
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')flag=1;
else if(ch>='0' && ch<='9')res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';
return flag ? -res : res;
}
struct node
{
int p,a,b;
}Q[maxx];
map<int,int >vis;
stack<int >s1,s2,s3;
bool cmp(node A,node B)
{
if(A.p!=B.p)
return A.p>B.p;//价格排序 因为用到stack 所以最大值放最前面
}
int c[maxx];
int main()
{
int n,m,x;
scanf("%d",&n);
for(int i=1;i<=n;i++)
Q[i].p=Scan();
for(int i=1;i<=n;i++)
Q[i].a=Scan();
for(int i=1;i<=n;i++)
Q[i].b=Scan();
sort(Q+1,Q+n+1,cmp);
scanf("%d",&m);
for(int i=1;i<=n;i++)
{
vis[Q[i].p]=0;
if(Q[i].a==1||Q[i].b==1)
s1.push(Q[i].p);//分三个stack分别在1-2-3颜色里找衣服的价格
if(Q[i].a==2||Q[i].b==2)
s2.push(Q[i].p);
if(Q[i].a==3||Q[i].b==3)
s3.push(Q[i].p);
}
for(int i=1;i<=m;i++)
{
int flag=0;
scanf("%d",&x);
if(x==1)
{
while(!s1.empty())
{
int h=s1.top();
s1.pop();
if(vis[h]==0)
{
printf("%d ",h);
vis[h]=1;
flag=1;
break;
}
}
if(!flag)
printf("-1 ");
}
if(x==2)
{
while(!s2.empty())
{
int h=s2.top();
s2.pop();
if(vis[h]==0)
{
printf("%d ",h);
vis[h]=1;
flag=1;
break;
}
}
if(!flag)
printf("-1 ");
}
if(x==3)
{
while(!s3.empty())
{
int h=s3.top();
s3.pop();
if(vis[h]==0)
{
printf("%d ",h);
vis[h]=1;
flag=1;
break;
}
}
if(!flag)
printf("-1 ");
}
}
}