QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#687 | #397960 | #8079. Range Periodicity Query | N_z_ | dengziyue | Success! | 2024-06-15 12:09:11 | 2024-06-15 12:10:15 |
詳細信息
Extra Test:
Wrong Answer
time: 21ms
memory: 122788kb
input:
120 pxraaaaaaaaaaaaaaaaaaaaaaaaaaaaaabvpaaaaaaaapvbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarxpqpwldkslaksodpsodlfkvmcxzndjekdlvvkfndsm 1 40 1 80 1 1
output:
40
result:
wrong answer 1st lines differ - expected: '-1', found: '40'
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397960 | #8079. Range Periodicity Query | dengziyue | WA | 1080ms | 179964kb | C++14 | 2.5kb | 2024-04-24 20:42:30 | 2024-06-15 12:12:15 |
answer
#include<bits/stdc++.h>
using namespace std;
#define max_n 1200000
#define mod 2008071523ll
#define inf 0x3f3f3f3f
long long pw[max_n+2];
long long inv[max_n+2];
int n;
int m;
int q;
int a[max_n+2];
char op[max_n+2];
struct Q{int id,l,r;};
vector<Q>que[max_n+2];
vector<int>g[max_n+2];
int s[max_n+2];
int sl[max_n+2],sr[max_n+2];
long long sum[max_n+2];
vector<int>del[max_n+2];
struct T{int l,r,mi;}tr[max_n<<2];
int ans[max_n+2];
inline long long qp(long long a,long long b){
long long res=1;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod; b>>=1;
}
return res;
}
inline long long askhs(int l,int r){return (sum[r]-sum[l-1]+mod)%mod*inv[l]%mod;}
bool check(int x,int k){
if(x<=k)return true;
return askhs(sl[x],sr[x]-k)==askhs(sl[x]+k,sr[x]);
}
void pu(int o){tr[o].mi=min(tr[o<<1].mi,tr[o<<1|1].mi);}
void build(int o,int l,int r){
tr[o]=(T){l,r,inf};
if(l>=r)return;
int mid=(l+r)>>1;
build(o<<1,l,mid);
build(o<<1|1,mid+1,r);
}
void upd(int o,int x,int w){
int l=tr[o].l,r=tr[o].r;
if(l>=r){tr[o].mi=w; return;}
int mid=(l+r)>>1;
if(x<=mid)upd(o<<1,x,w);
else upd(o<<1|1,x,w);
pu(o);
}
int query(int o,int ql,int qr){
int l=tr[o].l,r=tr[o].r;
if(ql<=l&&r<=qr)return tr[o].mi;
int mid=(l+r)>>1,res=inf;
if(ql<=mid)res=min(res,query(o<<1,ql,qr));
if(qr>mid)res=min(res,query(o<<1|1,ql,qr));
return res;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("QOJ8079_1.in","r",stdin);
freopen("QOJ8079_1.out","w",stdout);
#endif
pw[0]=inv[0]=1; pw[1]=27; inv[1]=qp(pw[1],mod-2);
for(int i=2;i<=max_n;++i){pw[i]=pw[i-1]*pw[1]%mod; inv[i]=inv[i-1]*inv[1]%mod;}
scanf("%d%s%d",&m,op+1,&n);
for(int i=1;i<=n;++i)scanf("%d",a+i);
scanf("%d",&q);
for(int i=1,k,l,r;i<=q;++i){
scanf("%d%d%d",&k,&l,&r); que[k].push_back((Q){i,l,r});
}
for(int i=1;i<=n;++i)g[a[i]].push_back(i);
sl[0]=m+1; sr[0]=m;
for(int i=1;i<=m;++i){
sl[i]=sl[i-1]; sr[i]=sr[i-1];
if(op[i]>='a'&&op[i]<='z')s[--sl[i]]=op[i]-'a'+1;
else s[++sr[i]]=op[i]-'A'+1;
}
sum[0]=0;
for(int i=1;i<=m*2;++i)sum[i]=(sum[i-1]+s[i]*pw[i]%mod)%mod;
for(int k=1;k<=m;++k){
int pos=k;
for(int l=k+1,r=m,mid;l<=r;){
mid=(l+r)>>1;
if(check(mid,k)){l=mid+1; pos=mid;}
else r=mid-1;
}
del[pos+1].push_back(k);
}
build(1,1,n);
for(int i=1;i<=m;++i){
for(auto v:g[i])upd(1,v,a[v]);
for(auto u:del[i]){
for(auto v:g[u])upd(1,v,inf);
}
for(auto u:que[i])ans[u.id]=query(1,u.l,u.r);
}
for(int i=1;i<=q;++i){
if(ans[i]<inf)printf("%d\n",ans[i]);
else printf("-1\n");
}
return 0;
}