其实和bzoj2724是一样的
都是先处理多个块的答案,然后多余部分暴力
空间要注意一下,还是O(nsqrt(n));
1 var f:array[0..320,0..320] of longint; 2 g:array[0..317,0..100001] of longint; 3 a,s,be:array[0..100001] of longint; 4 t,n,p,m,i,x,y,ans,size:longint; 5 6 procedure swap(var a,b:longint); 7 var c:longint; 8 begin 9 c:=a; 10 a:=b; 11 b:=c; 12 end; 13 14 function min(a,b:longint):longint; 15 begin 16 if a>b then exit(b) else exit(a); 17 end; 18 19 procedure pre; 20 var i,j,k:longint; 21 begin 22 for i:=1 to t do 23 begin 24 k:=min(n,i*size); 25 g[i]:=g[i-1]; 26 for j:=(i-1)*size+1 to k do 27 inc(g[i,a[j]]); 28 end; 29 for i:=1 to t do 30 begin 31 fillchar(s,sizeof(s),0); 32 for j:=(i-1)*size+1 to n do 33 begin 34 inc(s[a[j]]); 35 if j=(be[j]-1)*size+1 then 36 f[i,be[j]]:=f[i,be[j]-1]; 37 if s[a[j]]>=2 then 38 if s[a[j]] mod 2=1 then dec(f[i,be[j]]) else inc(f[i,be[j]]); 39 end; 40 end; 41 end; 42 43 procedure clear(x,y:longint); 44 var i:longint; 45 begin 46 for i:=x to y do 47 s[a[i]]:=0; 48 end; 49 50 function ask(x,y:longint):longint; 51 var i:longint; 52 begin 53 ask:=0; 54 if be[x]=be[y] then 55 begin 56 for i:=x to y do 57 begin 58 inc(s[a[i]]); 59 if s[a[i]]>=2 then 60 if s[a[i]] mod 2=1 then dec(ask) else inc(ask); 61 end; 62 clear(x,y); 63 end 64 else begin 65 ask:=f[be[x]+1,be[y]-1]; 66 for i:=x to be[x]*size do 67 begin 68 if s[a[i]]=0 then s[a[i]]:=g[be[y]-1,a[i]]-g[be[x],a[i]]; 69 inc(s[a[i]]); 70 if s[a[i]]>=2 then 71 if s[a[i]] mod 2=1 then dec(ask) else inc(ask); 72 end; 73 for i:=(be[y]-1)*size+1 to y do 74 begin 75 if s[a[i]]=0 then s[a[i]]:=g[be[y]-1,a[i]]-g[be[x],a[i]]; 76 inc(s[a[i]]); 77 if s[a[i]]>=2 then 78 if s[a[i]] mod 2=1 then dec(ask) else inc(ask); 79 end; 80 clear(x,be[x]*size); 81 clear((be[y]-1)*size+1,y); 82 end; 83 end; 84 85 begin 86 readln(n,p,m); 87 size:=trunc(sqrt(n)); 88 for i:=1 to n do 89 begin 90 read(a[i]); 91 be[i]:=(i-1) div size+1; 92 end; 93 t:=n div size; 94 if n mod size<>0 then inc(t); 95 pre; 96 fillchar(s,sizeof(s),0); 97 for i:=1 to m do 98 begin 99 readln(x,y); 100 x:=(x+ans) mod n+1; 101 y:=(y+ans) mod n+1; 102 if x>y then swap(x,y); 103 ans:=ask(x,y); 104 writeln(ans); 105 end; 106 end.