传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=3916
题目大意
串S复制一遍接到S后面,然后任意位置插一个字符得到串U
给定串U,询问串S
题解
暴力+HASH
尼玛,给的Sample Input x:我真以为他是多组询问我还要输出Sample Output x:,WAWAW
const
maxn=2000010;
seed=131;
mmod=maxlongint;
var
hash,pow:array[0..maxn]of int64;
x:array[0..maxn]of char;
i,j,k,l:longint;
n,m,ansl,ansr:longint;
t1,t2,ans:int64;
cha:char;
function query(l,r:longint):int64;
begin
if l>r then exit(0);
if l<1 then exit(0);
if r>n then exit(0);
exit((hash[r]-(hash[l-1]*pow[r-l+1])mod mmod+mmod)mod mmod);
end;
begin
ansl:=0; ansr:=0; ans:=0;
readln(n); hash[0]:=0; pow[0]:=1;
for i:=1 to n do
begin
read(x[i]);
hash[i]:=(hash[i-1]*seed+ord(x[i]))mod mmod;
pow[i]:=(pow[i-1]*seed)mod mmod;
end;
readln;
m:=(n-1)div 2;
if (n mod 2)<>0
then
for i:=1 to n do
begin
if i<=m+1
then begin t1:=(query(i+1,m+1)+query(1,i-1)*pow[m-i+1])mod mmod; t2:=query(n-m+1,n); end
else begin t1:=query(1,m); t2:=(query(i+1,n)+query(m+1,i-1)*pow[n-i])mod mmod; end;
if t1=t2
then
begin
if (ans<>0)and(t1<>ans) then begin ansl:=-1; break; end;
if i<m+1
then begin ansl:=n-m+1; ansr:=n; ans:=t1; end
else begin ansl:=1; ansr:=m; ans:=t1; end;
end;
end;
if (ansl=0)and(ansr=0)
then writeln('NOT POSSIBLE')
else
if ansl=-1
then writeln('NOT UNIQUE')
else
begin
for i:=ansl to ansr do
write(x[i]);
writeln;
end;
end.