Codeforces 215B B.Sereja and Suffixes
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> int sum; int n,m; int a[100010]; int l[100010]; int s[100010]; int map[100010]; int main() { while(~scanf("%d%d",&n,&m)) { memset(a,0,sizeof(a)); memset(l,0,sizeof(l)); memset(s,0,sizeof(s));; for(int i = 1;i <= n;i ++) scanf("%d",&a[i]); map[n] = 1; s[a[n]] = 1; for(int i = n - 1;i >= 1;i --) { if(s[a[i]] == 0) { map[i] = map[i + 1] + 1; s[a[i]] = 1; } else map[i] = map[i + 1]; //printf("%d\n",map[i]); } int c; for(int i = 1;i <= m;i ++) { scanf("%d",&c); printf("%d\n",map[c]); } } return 0; }
思路:
代码: