QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398088#8079. Range Periodicity QuerymaoyitingWA 235ms81240kbC++141.6kb2024-04-24 22:06:222024-04-24 22:06:22

Judging History

你现在查看的是最新测评结果

  • [2024-06-15 15:38:16]
  • hack成功,自动添加数据
  • (/hack/699)
  • [2024-06-15 15:32:38]
  • hack成功,自动添加数据
  • (/hack/698)
  • [2024-06-15 15:28:06]
  • hack成功,自动添加数据
  • (/hack/696)
  • [2024-06-15 15:23:18]
  • hack成功,自动添加数据
  • (/hack/695)
  • [2024-06-15 15:03:19]
  • hack成功,自动添加数据
  • (/hack/694)
  • [2024-06-15 12:23:52]
  • hack成功,自动添加数据
  • (/hack/689)
  • [2024-06-15 12:15:05]
  • hack成功,自动添加数据
  • (/hack/688)
  • [2024-06-15 12:11:26]
  • hack成功,自动添加数据
  • (/hack/687)
  • [2024-06-15 12:07:23]
  • hack成功,自动添加数据
  • (/hack/686)
  • [2024-06-15 12:02:06]
  • hack成功,自动添加数据
  • (/hack/684)
  • [2024-06-15 11:50:54]
  • hack成功,自动添加数据
  • (/hack/682)
  • [2024-06-15 11:45:20]
  • hack成功,自动添加数据
  • (/hack/681)
  • [2024-06-15 11:39:29]
  • hack成功,自动添加数据
  • (/hack/680)
  • [2024-04-24 22:06:22]
  • 评测
  • 测评结果:WA
  • 用时:235ms
  • 内存:81240kb
  • [2024-04-24 22:06:22]
  • 提交

answer

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

详细

Test #1:

score: 100
Accepted
time: 9ms
memory: 65320kb

input:

7
AABAAba
9
4 3 2 1 7 5 3 6 1
6
1 4 4
2 1 4
2 1 3
3 3 5
5 4 7
7 8 9

output:

1
1
2
-1
3
6

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 235ms
memory: 81240kb

input:

200000
BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

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