当前位置:网站首页>C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
2022-06-25 22:01:00 【秦三马】
C. Yet Another Card Deck
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You have a card deck of nn cards, numbered from top to bottom, i. e. the top card has index 11 and bottom card — index nn. Each card has its color: the ii-th card has color aiai.
You should process qq queries. The jj-th query is described by integer tjtj. For each query you should:
- find the highest card in the deck with color tjtj, i. e. the card with minimum index;
- print the position of the card you found;
- take the card and place it on top of the deck.
Input
The first line contains two integers nn and qq (2≤n≤3⋅1052≤n≤3⋅105; 1≤q≤3⋅1051≤q≤3⋅105) — the number of cards in the deck and the number of queries.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤501≤ai≤50) — the colors of cards.
The third line contains qq integers t1,t2,…,tqt1,t2,…,tq (1≤tj≤501≤tj≤50) — the query colors. It's guaranteed that queries ask only colors that are present in the deck.
Output
Print qq integers — the answers for each query.
Example
input
Copy
7 5 2 1 1 4 3 3 1 3 2 1 1 4
output
Copy
5 2 3 1 5
Note
Description of the sample:
- the deck is [2,1,1,4,3–,3,1][2,1,1,4,3_,3,1] and the first card with color t1=3t1=3 has position 55;
- the deck is [3,2–,1,1,4,3,1][3,2_,1,1,4,3,1] and the first card with color t2=2t2=2 has position 22;
- the deck is [2,3,1–,1,4,3,1][2,3,1_,1,4,3,1] and the first card with color t3=1t3=1 has position 33;
- the deck is [1–,2,3,1,4,3,1][1_,2,3,1,4,3,1] and the first card with color t4=1t4=1 has position 11;
- the deck is [1,2,3,1,4–,3,1][1,2,3,1,4_,3,1] and the first card with color t5=4t5=4 has position 55.
===============================================================================================================
自始至终,我们只需要统计50种以内颜色第一次出现的位置,因为一旦点到这个颜色我们还是要将他放在第一个位置,始终覆盖着和它颜色相同但是位置靠下的卡片。暴力模拟即可。
#include<iostream>
using namespace std;
int id[100];
int main()
{
int n,t;
cin>>n>>t;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(!id[x])
id[x]=i;
}
for(int i=1;i<=t;i++)
{
int pos;
int color;
cin>>color;
cout<<id[color]<<" ";
pos=id[color];
id[color]=1;
for(int i=1;i<=50;i++)
{
if(i!=color&&id[i]&&id[i]<pos)
{
id[i]++;
}
}
}
return 0;
}
边栏推荐
- STM32 development board + smart cloud aiot+ home monitoring and control system
- Baidu: in 2022, the top ten hot spots will rise and the profession will be released. There is no suspense about the first place!
- The sum of logarithms in group 52--e of Niuke Xiaobai monthly race (two points)
- Qt Utf8 与 Unicode 编码的互相转换, Unicode编码输出为格式为 &#xXXXX
- hiberate核心API/配置文件/一级缓存详解
- [untitled] open an item connection. If it cannot be displayed normally, Ping the IP address
- User interaction scanner usage Advanced Edition example
- OBS-Studio-27.2.4-Full-Installer-x64.exe 下载
- Es7/es9 -- new features and regularities
- Xampp重启后,MySQL服务就启动不了。
猜你喜欢

Actual combat: how to quickly change font color in typera (blog sharing - perfect) -2022.6.25 (solved)

Why is the frame rate calculated by opencv wrong?

hiberate实体类CURD、事务操作汇总

【ModuleBuilder】GP服务实现SDE中两个图层相交选取

character string

百度:2022年十大热度攀升专业出炉,第一名无悬念!

LM小型可编程控制器软件(基于CoDeSys)笔记十七:pto脉冲功能块

hiberate核心API/配置文件/一级缓存详解

Idea shortcut

UE4 学习记录二 给角色添加骨架,皮肤,及运动动画
随机推荐
Leaky API interface practical development series (13): gooseneck cloud service php-api two-dimensional array parameter transfer solution
Multithreaded learning 2- call control
Implementation of sequence table: static and dynamic
解决‘tuple‘ object has no attribute ‘lower‘
Go语言逃逸分析全纪录
[opencv450 samples] create image list yaml
Ue4 Ue5 combine le plug - in de reconnaissance vocale de bureau pour la reconnaissance vocale
hiberate实体类CURD、事务操作汇总
【opencv450-samples】读取图像路径列表并保持比例显示
Flex & Bison 開始
cookie、session、token
判断预约时间是否已经过期
Leetcode(605)——种花问题
Technology blog site collection
Kubernetes cluster construction of multiple ECS
电路模块分析练习5(电源)
Comp2913 database
记录一下Qt将少量图片输出为MP4的思路及注意事项
Idea auto generator generates constructor get/set methods, etc
QLabel 文字水平滚动显示