1 #include <iostream>
2 #include <cstring>
3 #include <string>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cmath>
7 #include <algorithm>
8 #include <queue>
9 #include <stack>
10 #include <map>
11 #include <set>
12 #include <list>
13 #include <vector>
14 #include <ctime>
15 #include <functional>
16 #define pritnf printf
17 #define scafn scanf
18 #define sacnf scanf
19 #define For(i,j,k) for(int i=(j);i<=(k);(i)++)
20 #define Clear(a) memset(a,0,sizeof(a))
21 using namespace std;
22 typedef unsigned int Uint;
23 const int INF=0x3fffffff;
24 const double eps=1e-10;
25 ///==============struct declaration==============
26 struct Querys{
27 int st,ed,No;
28 bool operator <(const Querys &rhs) const{
29 return st==rhs.st?ed<rhs.ed:st<rhs.st;
30 }
31 };
32 ///==============var declaration=================
33 const int MAXN=1000100;
34 int n,c,m;
35 int color[MAXN],pos[MAXN],next[MAXN];
36 int A[MAXN],ans[MAXN];
37 Querys Query[MAXN];
38 ///==============function declaration============
39 void Add_Bit(int x,int v);
40 int Query_Bit(int x);
41 int lowbit(int x){return x&-x;}
42 ///==============main code=======================
43 int main()
44 {
45 #define FILE__
46 #ifdef FILE__
47 freopen("input.txt","r",stdin);
48 freopen("output.txt","w",stdout);
49 #endif
50 scanf("%d%d%d",&n,&c,&m);
51 for(int i=1;i<=n;i++) scanf("%d",color+i);
52 for(int i=n;i>=1;i--){
53 next[i]=pos[color[i]];
54 pos[color[i]]=i;
55 }
56 for(int i=1;i<=c;i++)
57 if (next[pos[i]])
58 Add_Bit(next[pos[i]],1);
59 for(int i=1;i<=m;i++){
60 scanf("%d%d",&Query[i].st,&Query[i].ed);
61 Query[i].No=i;
62 }
63 sort(Query+1,Query+1+m);
64 int L=1;
65 for(int i=1;i<=m;i++){
66 while (L<Query[i].st){
67 if (next[next[L]])
68 Add_Bit(next[next[L]],1);
69 if (next[L])
70 Add_Bit(next[L],-1);
71 L++;
72 }
73 ans[Query[i].No]=Query_Bit(Query[i].ed)-Query_Bit(Query[i].st-1);
74 }
75 for(int i=1;i<=m;i++)
76 printf("%d\n",ans[i]);
77 return 0;
78 }
79 ///================fuction code====================
80 void Add_Bit(int x,int v){
81 while (x<=n){
82 A[x]+=v;
83 x+=lowbit(x);
84 }
85 }
86 int Query_Bit(int x){
87 int res=0;
88 while (x>0){
89 res+=A[x];
90 x-=lowbit(x);
91 }
92 return res;
93 }