CF-799B
B. T-shirt buyingtime limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi is back color of the i-th t-shirt. All values pi are distinct, and values ai and bi are integers from 1 to 3.
m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color cj.
A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.
You are to compute the prices each buyer will pay for t-shirts.
InputThe first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts.
The following line contains sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ 1 000 000 000), where pi equals to the price of the i-th t-shirt.
The following line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3), where ai equals to the front color of the i-th t-shirt.
The following line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 3), where bi equals to the back color of the i-th t-shirt.
The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.
The following line contains sequence c1, c2, ..., cm (1 ≤ cj ≤ 3), where cj equals to the favorite color of the j-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.
OutputPrint to the first line m integers — the j-th integer should be equal to the price of the t-shirt which the j-th buyer will buy. If the j-th buyer won't buy anything, print -1.
Examplesinput5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1output200 400 300 500 911 -1input2
1000000000 1
1 1
1 2
2
2 1output1 1000000000
题意:
有n件T恤,每件含有三个属性价格v,正面颜色f和反面颜色b。
现有m个顾客,每个顾客有要买最喜欢的颜色中最便宜的一件。
用set对所有衣服储存并排序,卖出一件就将这件删除。
附AC代码:
#include<bits/stdc++.h>
using namespace std; const int N=2e5+; struct node{
int v,f,b;
}a[N]; set<int> s[]; int main(){
int n,m;
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i].v;
}
for(int i=;i<=n;i++){
cin>>a[i].f;
}
for(int i=;i<=n;i++){
cin>>a[i].b;
}
for(int i=;i<=n;i++){
s[a[i].f].insert(a[i].v);
s[a[i].b].insert(a[i].v);
}
cin>>m;
for(int i=;i<=m;i++){
int x;
cin>>x;
if(s[x].size()==){
cout<<"-1"<<" ";
continue;
}
else{
int temp=*(s[x].begin());
cout<<temp<<" ";
for(int j=;j<=;j++){
s[j].erase(temp);
}
}
}
return ;
}
CF-799B的更多相关文章
- CF 799B T-shirt buying
一道超级水的练习STL的题目 题目大意:有\(n\)件T恤,每件T恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种属性.接下来有\(m\)个人每个人都有一种喜欢的颜色,他们按先后顺序 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
随机推荐
- 读《疯狂Java讲义》笔记总结三
1.初始化块 实际上初始化块是一个假象,使用javac命令编译Java类后,该Java类中的初始化块会消失--初始化块中代码会被 "还原" 到每一个构造器中,且位于构造器全部代码的 ...
- EC2的维护更新
2014年9月28日 近期几天.我们收到了一些客户关于我们即将进行维护更新的问题.下面是AWS全球Blog网站对这个问题的说明,供客户參照. 我们已经開始通知那些受影响的客户,关于我们即将实施的 ...
- restframework-总结
1. 规范 - 版本控制 - 部署专用的域名(防止跨域攻击) - 因为restframework又称为面向资源的编程所以url名词需要用专业的名词去表示 - 请求方式method - url上可以传递 ...
- Mac OS command line TestNG - “Cannot find class in classpath” error
直接eclipse执行.xml文件可以正确执行 在mac下执行却总报错: [TestNG] [Error] Cannot find class in classpath 最后解决办法,classpat ...
- android启动另一应用
http://www.2cto.com/kf/201203/122910.html Android SDK中有这样一个API: public abstract Intent getLaunchInte ...
- Storage,Memcache,KVDB都是存储服务,如何区分何时用何种服务
Storage :是SAE为开发者提供的分布式文件存储服务,用来存放用户的持久化存储的文件.用户需要先在在线管理平台创建Domain(相当于一级子目录). Storage为开发者提供分布式文件存 ...
- UML类图关系表示方法
本文转载: http://blog.csdn.net/fengsh998/article/details/8105631 分类: UML2012-10-24 10:18 1175人阅读 评论(0) 收 ...
- mongodb学习之:安全和认证
mongodb默认是不认证的,默认没有账号,只要能连接上服务就可以对数据库进行各种操作,mongodb认为安全最好的方法就是在一个可信的环境中运行它,保证之后可信的机器才能访问它.因此需要在登录的时候 ...
- Mongoose学习(3)--设置环境变量
比如我一套代码数据库代码分为中文站和英文站,每个表中我都有一个site_code字段来区分, 两个站点部署在不同的人服务器,这个时候我们就用系统环境变量来区分, 下面直接在mac下设置环境变量 vim ...
- AndroidPageObjectTest_TimeOutManagement.java
以下代码使用ApiDemos-debug.apk进行测试 //这个脚本用于演示PageFactory的功能:设置timeout时间. package com.saucelabs.appium; imp ...