其实和bzoj2724是一样的
都是先处理多个块的答案,然后多余部分暴力
空间要注意一下,还是O(nsqrt(n));

 var f:array[..,..] of longint;
g:array[..,..] of longint;
a,s,be:array[..] of longint;
t,n,p,m,i,x,y,ans,size:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure pre;
var i,j,k:longint;
begin
for i:= to t do
begin
k:=min(n,i*size);
g[i]:=g[i-];
for j:=(i-)*size+ to k do
inc(g[i,a[j]]);
end;
for i:= to t do
begin
fillchar(s,sizeof(s),);
for j:=(i-)*size+ to n do
begin
inc(s[a[j]]);
if j=(be[j]-)*size+ then
f[i,be[j]]:=f[i,be[j]-];
if s[a[j]]>= then
if s[a[j]] mod = then dec(f[i,be[j]]) else inc(f[i,be[j]]);
end;
end;
end; procedure clear(x,y:longint);
var i:longint;
begin
for i:=x to y do
s[a[i]]:=;
end; function ask(x,y:longint):longint;
var i:longint;
begin
ask:=;
if be[x]=be[y] then
begin
for i:=x to y do
begin
inc(s[a[i]]);
if s[a[i]]>= then
if s[a[i]] mod = then dec(ask) else inc(ask);
end;
clear(x,y);
end
else begin
ask:=f[be[x]+,be[y]-];
for i:=x to be[x]*size do
begin
if s[a[i]]= then s[a[i]]:=g[be[y]-,a[i]]-g[be[x],a[i]];
inc(s[a[i]]);
if s[a[i]]>= then
if s[a[i]] mod = then dec(ask) else inc(ask);
end;
for i:=(be[y]-)*size+ to y do
begin
if s[a[i]]= then s[a[i]]:=g[be[y]-,a[i]]-g[be[x],a[i]];
inc(s[a[i]]);
if s[a[i]]>= then
if s[a[i]] mod = then dec(ask) else inc(ask);
end;
clear(x,be[x]*size);
clear((be[y]-)*size+,y);
end;
end; begin
readln(n,p,m);
size:=trunc(sqrt(n));
for i:= to n do
begin
read(a[i]);
be[i]:=(i-) div size+;
end;
t:=n div size;
if n mod size<> then inc(t);
pre;
fillchar(s,sizeof(s),);
for i:= to m do
begin
readln(x,y);
x:=(x+ans) mod n+;
y:=(y+ans) mod n+;
if x>y then swap(x,y);
ans:=ask(x,y);
writeln(ans);
end;
end.
05-08 14:49