codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying
来源:互联网 发布:目标 知乎 编辑:程序博客网 时间:2024/05/21 14:42
B. T-shirt buying*
time limit per test 3 seconds
memory limit per test 256 megabytes
input standard input
output standard 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.
Input
The 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.
Output
Print 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.
Examples
input
5
300 200 400 500 911
1 2 1 2 3
2 1 3 2 1
6
2 3 1 2 1 1
output
200 400 300 500 911 -1
input
2
1000000000 1
1 1
1 2
2
2 1
output
1 1000000000
#include<bits/stdc++.h>using namespace std;int n,m;#define N 210001#define PER(i,a,b) for(int i=a;i<=b;i++)int a[N],b[N];int p[N];int c[N];bool pg[4][4];int t[4][4][2*N];int size[4][4];void up(int x,int y,int k){ while(k>1&&t[x][y][k]<t[x][y][k/2]) { swap(t[x][y][k],t[x][y][k/2]); k/=2; }}void down(int x,int y,int k){ int j; int le=k*2,ri=le+1; while(le<=size[x][y]) { if(le==size[x][y]||t[x][y][le]<t[x][y][ri]) j=le;else j=ri; if(t[x][y][j]<t[x][y][k]) swap(t[x][y][j],t[x][y][k]); else return; k=j;le=k*2,ri=le+1; } return;}void add(int x,int y,int p){ int num=++size[x][y]; t[x][y][num]=p;up(x,y,num);}int co;int back,on[4];int QwQ;int bb,cc;int main(){ scanf("%d",&n); PER(i,1,n) scanf("%d",&p[i]); PER(i,1,3)PER(j,1,3)PER(xx,1,n+1) t[i][j][xx]=2e9; PER(i,1,n)scanf("%d",&a[i]);PER(i,1,n)scanf("%d",&b[i]); PER(i,1,n) if(a[i]>b[i]) swap(a[i],b[i]); PER(i,1,n) add(a[i],b[i],p[i]); scanf("%d",&m); PER(i,1,m) { scanf("%d",&co); PER(j,1,3) { bb=co;cc=j; if(bb>cc) swap(bb,cc); on[j]=t[bb][cc][1]; } QwQ=2e9; PER(j,1,3) {if(QwQ>on[j]) {back=j;QwQ=on[j];}}if(back==0||QwQ>1e9+4001) QwQ=-1; printf("%d ",QwQ); bb=co;cc=back;if(bb>cc) swap(bb,cc);t[bb][cc][1]=2e9+5;down(bb,cc,1); }}
> 这里的算法非常暴力,建衣服前后两面为集合(1,2),(1,3),(2,3),(1,1),(2,2),(3,3)共6个堆,然后就可以暴力乱弹,对每个询问比一下大小弹个堆即可。其实是可以用三个优先队列,维护一下有没有被取过来解决的,但复杂度没我这个优。
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) B. T-shirt buying
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)A题
- CodeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)C题C. Fountains
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) B
- Codeforces Round #413 Div. 1 + Div. 2 B. T-shirt buying
- Codeforces Round #413 (Div.1 + Div. 2) B. T-shirt buying
- codeforces Round #413 Div. 1 + Div. 2 B T-shirt buying
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) A题
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) B. T-Shirt Hunt(模拟)
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains(树状数组)
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains 乱搞
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) A. Carrot Cakes
- [Updating] Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 解题报告
- Codeforces Round #413 B. T-shirt buying
- Codeforces Round #413 B. T-shirt buying
- (Codeforces Round #413, rated, Div. 1 + Div. 2)(A+B)
- 建造者模式【Builder Pattern】
- Activity使用技巧
- httpclient访问未知证书的https网站
- Echarts入门--直方图、折线图
- 【GraphLite】同步图运算初试-数三角形
- codeforcesPlayrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)B题B. T-shirt buying
- 传统物体检测
- 蓝桥杯
- 加密解密(四)--Java中的Hash算法
- centos6.6下mysql-5.6.21源码安装
- numpy常用函数笔记
- ZooKeeper架构设计及其应用要点
- ORB-SLAM2跟踪之估计初始位姿
- JS事件&DOM初体验