cf B. Sereja and Suffixes

时间:2022-05-16 04:17:53

http://codeforces.com/contest/368/problem/B

从后往前找一遍就可以。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
using namespace std; int dp[maxn];
int n,m;
int a[maxn];
bool vis[maxn]; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,,sizeof(dp));
memset(vis,false,sizeof(vis));
int t1=;
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(int i=n; i>=; i--)
{
if(!vis[a[i]])
{
vis[a[i]]=true;
t1++;
dp[i]=t1;
}
else
{
dp[i]=t1;
}
}
for(int i=; i<=m; i++)
{
int x;
scanf("%d",&x);
printf("%d\n",dp[x]);
}
}
return ;
}