QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#688#398109#8079. Range Periodicity Queryship2077maoyitingSuccess!2024-06-15 12:10:052024-06-15 12:13:56

詳細信息

Extra Test:

Wrong Answer
time: 0ms
memory: 63488kb

input:

100
pyajfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaabbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1
50
1
100 1 1

output:

50

result:

wrong answer 1st lines differ - expected: '-1', found: '50'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398109#8079. Range Periodicity QuerymaoyitingWA 830ms95816kbC++141.5kb2024-04-24 22:15:492024-06-15 12:15:48

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+5,mod=1e9+7;
int n,m,q,a[N],L[N],R[N],c=131,p[N],h[N],M,mn[N<<2],ans[N];
char t[N],s[N];
vector<pair<int,int> >v[N];
vector<array<int,3> >Q[N];
int qry(int l,int r){
	return (h[r]-1ll*h[l-1]*p[r-l+1]%mod+mod)%mod;
}
void modify(int p,int v){
	mn[p+=M]=v;
	for(p>>=1;p;p>>=1) mn[p]=min(mn[p<<1],mn[p<<1|1]);
}
int query(int l,int r){
	int ans=1e9;
	for(l+=M-1,r+=M+1;l^1^r;l>>=1,r>>=1){
		if(!(l&1)) ans=min(ans,mn[l^1]);
		if(r&1) ans=min(ans,mn[r^1]);
	}
	return ans;
}
signed main(){
	scanf("%d%s",&n,t+1);
	int l=5e5+1,r=l-1;
	for(int i=1;i<=n;i++){
		if(islower(t[i])) s[--l]=t[i];
		else s[++r]=t[i]-'A'+'a';
		L[i]=l,R[i]=r;
	}
	for(int i=l;i<=r;i++) s[i-l+1]=s[i];
	p[0]=1;
	for(int i=1;i<=n;i++)
		p[i]=1ll*p[i-1]*c%mod,h[i]=(1ll*h[i-1]*c+s[i])%mod,
		L[i]-=l-1,R[i]-=l-1;
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&a[i]);
		int l=a[i],r=n,p=0;
		while(l<=r){
			int mid=(l+r)/2;
			if(qry(L[mid],R[mid]-a[i])==qry(L[mid]+a[i],R[mid])) p=mid,l=mid+1;
			else r=mid-1;
		}
		v[a[i]].push_back({i,a[i]}),v[p+1].push_back({i,1e9});
	}
	scanf("%d",&q);
	for(int i=1,k,l,r;i<=q;i++)
		scanf("%d%d%d",&k,&l,&r),
		Q[k].push_back({l,r,i});
	for(M=1;M<m+2;M<<=1);
	fill(mn,mn+2+M+m,1e9);
	for(int i=1;i<=n;i++){
		for(auto p:v[i]) modify(p.first,p.second);
		for(auto p:Q[i]) ans[p[2]]=query(p[0],p[1]);
	}
	for(int i=1;i<=q;i++)
		printf("%d\n",ans[i]<1e9?ans[i]:-1);
	return 0;
}