QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#699 | #443449 | #8079. Range Periodicity Query | N_z_ | N_z_ | Success! | 2024-06-15 15:37:07 | 2024-06-15 15:37:07 |
詳細信息
Extra Test:
Wrong Answer
time: 20ms
memory: 59332kb
input:
101376 aaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaaphtlaaaatmaapht...
output:
25344
result:
wrong answer 1st lines differ - expected: '-1', found: '25344'
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#443449 | #8079. Range Periodicity Query | N_z_ | WA | 1253ms | 198484kb | C++14 | 2.3kb | 2024-06-15 15:35:56 | 2024-06-15 15:40:03 |
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ull unsigned long long
const int N=5e5+5,inf=1e9;
const ull mod1=1e9+7;
ull Mod1(ull w){return w>=mod1?w-mod1:w;}
struct nade{
ull h1,h2;
nade(ull a=0,ull b=0){h1=a;h2=b;}
nade operator * (const nade &w)const{return nade(h1*w.h1%mod1,h2*w.h2);}
nade operator + (const int &w)const{return nade(Mod1(h1+w),h2+w);}
nade operator - (const nade &w)const{return nade(Mod1(h1-w.h1+mod1),h2-w.h2);}
bool operator == (const nade &w)const{return h1==w.h1&&h2==w.h2;}
}H[N],pw[N];
int mn[N*25],ls[N*25],rs[N*25],cnt,n,ans[N],p[N],l[N],r[N],qk[N],ql[N],qr[N],la,rt[N];
vector<int>id[N],E[N];
char str[N],s[N*3];
void change(int &x,int l,int r,int p,int w){
if(x<=la){cnt++;mn[cnt]=mn[x];ls[cnt]=ls[x];rs[cnt]=rs[x];x=cnt;}
mn[x]=min(mn[x],w);if(l==r)return;
int mid=(l+r)>>1;
if(mid>=p)change(ls[x],l,mid,p,w);
else change(rs[x],mid+1,r,p,w);
}
int ask(int x,int l,int r,int L,int R){
if(!x||l>=L&&r<=R)return mn[x];
int mid=(l+r)>>1,rec=inf;
if(mid>=L)rec=ask(ls[x],l,mid,L,R);
if(mid+1<=R)rec=min(rec,ask(rs[x],mid+1,r,L,R));
return rec;
}
nade ask(int l,int r){return H[r]-H[l-1]*pw[r-l+1];}
bool chk(int l,int r,int len){
if(r-l+1<=len)return 1;
return ask(l,r-len)==ask(l+len,r);
}mt19937_64 rnd(time(NULL));
int main(){
scanf("%d%s",&n,str+1);
int L=n+1,R=n;
for(int i=1;i<=n;i++)
if('A'<=str[i]&&str[i]<='Z')s[++R]=str[i]-'A'+'a';
else s[--L]=str[i];
for(int i=1;i<=n;i++)s[i]=s[L+i-1];
nade base=nade(131,rnd());pw[0]=nade(1,1);
for(int i=1;i<=n;i++)pw[i]=pw[i-1]*base;
for(int i=1;i<=n;i++)H[i]=H[i-1]*base+(s[i]-'a'+1);
l[n]=1;r[n]=n;
for(int i=n;i>1;i--){
if('A'<=str[i]&&str[i]<='Z')l[i-1]=l[i],r[i-1]=r[i]-1;
else l[i-1]=l[i]+1,r[i-1]=r[i];
}p[1]=1;
for(int i=1;i<=n;i++){
int l=1,r=n,rec=0;
while(l<=r){
int mid=(l+r)>>1;
if(chk(::l[mid],::r[mid],i))rec=mid,l=mid+1;
else r=mid-1;
}E[rec].pb(i);
}mn[0]=inf;int m,q;scanf("%d",&m);
for(int i=1,d;i<=m;i++)scanf("%d",&d),id[d].pb(i);
for(int i=n;i>=1;i--){
la=cnt;rt[i]=rt[i+1];
for(int w:E[i])for(auto p:id[w])
change(rt[i],1,m,p,w);
}scanf("%d",&q);
for(int i=1,k,l,r;i<=q;i++){
scanf("%d%d%d",&k,&l,&r);
int rec=ask(rt[k],1,m,l,r);
printf("%d\n",rec>k?-1:rec);
}
}