其实和bzoj1878类似
只不过要求的是区间内数量多于1个的数字种数
其实还是按照bzoj1878做
只不过我们是把每一种数字下一个出现的位置+1,并把这个位置置为0
1 var x,y,ans,p,last,a,c,next:array[0..1000010] of longint; 2 max,i,n,m,j:longint; 3 4 function lowbit(x:longint):longint; 5 begin 6 exit(x and(-x)); 7 end; 8 9 function sum(x:longint):longint; 10 begin 11 sum:=0; 12 while x<>0 do 13 begin 14 sum:=sum+c[x]; 15 x:=x-lowbit(x); 16 end; 17 end; 18 19 procedure add(x,t:longint); 20 begin 21 while x<=n do 22 begin 23 inc(c[x],t); 24 x:=x+lowbit(x); 25 end; 26 end; 27 28 procedure swap(var a,b:longint); 29 var c:longint; 30 begin 31 c:=a; 32 a:=b; 33 b:=c; 34 end; 35 36 procedure sort(l,r: longint); 37 var i,j,z: longint; 38 begin 39 i:=l; 40 j:=r; 41 z:=x[(l+r) div 2]; 42 repeat 43 while x[i]do inc(i); 44 while z do dec(j); 45 if not(i>j) then 46 begin 47 swap(x[i],x[j]); 48 swap(y[i],y[j]); 49 swap(p[i],p[j]); 50 inc(i); 51 dec(j); 52 end; 53 until i>j; 54 if l then sort(l,j); 55 if i then sort(i,r); 56 end; 57 58 begin 59 readln(n,max,m); 60 for i:=1 to n do 61 read(a[i]); 62 63 for i:=1 to m do 64 begin 65 readln(x[i],y[i]); 66 p[i]:=i; 67 end; 68 sort(1,m); 69 fillchar(last,sizeof(last),0); 70 for i:=n downto 1 do 71 begin 72 next[i]:=last[a[i]]; 73 last[a[i]]:=i; 74 end; 75 for i:=1 to max do 76 if next[last[i]]<>0 then add(next[last[i]],1); 77 78 j:=1; 79 for i:=1 to n do 80 begin 81 while x[j]=i do 82 begin 83 ans[p[j]]:=sum(y[j])-sum(x[j]-1); 84 inc(j); 85 end; 86 if next[i]<>0 then add(next[i],-1); 87 if next[next[i]]<>0 then add(next[next[i]],1); 88 end; 89 for i:=1 to m do 90 writeln(ans[i]); 91 end.