QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397957#8079. Range Periodicity QuerydengziyueRE 617ms97628kbC++142.5kb2024-04-24 20:41:412024-04-24 20:41:41

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 20:41:41]
  • 评测
  • 测评结果:RE
  • 用时:617ms
  • 内存:97628kb
  • [2024-04-24 20:41:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define max_n 500000
#define mod 2008071523ll
#define inf 0x3f3f3f3f
long long pw[max_n*2+2];
long long inv[max_n*2+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+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*2;++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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 67588kb

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: 0
Accepted
time: 229ms
memory: 85816kb

input:

200000
BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
61006
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 500000 lines

Test #3:

score: 0
Accepted
time: 426ms
memory: 90428kb

input:

10
baaAaAAaAA
500000
6 8 2 3 1 8 7 3 9 4 1 6 9 4 10 10 4 3 1 7 4 3 9 7 1 2 9 3 3 1 10 8 1 6 4 1 6 10 1 5 1 8 9 9 7 3 6 3 9 1 7 6 7 7 9 10 3 2 4 10 7 3 7 1 5 3 5 1 10 1 3 2 2 4 2 3 4 10 5 2 7 10 5 6 8 9 10 6 9 7 5 4 5 4 4 2 5 8 1 9 1 2 10 8 2 5 6 6 6 4 3 1 2 2 3 5 7 4 5 7 5 8 1 8 9 7 6 3 10 7 5 4 8 8...

output:

5
4
4
2
6
3
3
4
6
3
1
6
4
5
3
5
2
5
4
4
2
5
3
5
5
1
2
5
3
5
4
3
5
6
4
5
4
6
4
6
4
1
5
4
4
3
5
3
3
4
5
5
5
4
1
6
5
5
4
4
2
4
3
5
4
5
1
5
1
1
4
4
5
4
4
3
3
4
2
4
4
4
2
4
6
5
2
5
4
3
4
2
4
5
5
4
6
1
2
6
4
5
6
1
1
3
2
3
1
4
4
3
4
4
4
3
6
5
4
5
5
4
1
2
3
4
5
4
4
4
3
6
4
4
4
2
3
3
3
3
3
6
3
5
3
4
6
3
4
5
...

result:

ok 500000 lines

Test #4:

score: 0
Accepted
time: 522ms
memory: 91224kb

input:

500
ababbBbBabaaBAbabBbbBBAAABabBbBAAABbaBbBAAbabaBaAAaabAaABBBabababAAbaaAbbAAabAAbBbaabbBbaAAABaAaBbbBbabBAABBaabbAabbBabbbAbABaBAABaBbAaaBABBbBAAbbbBabbABABAaAaAAAbaAabBbBaaaaAAAAAabaBBAAABAbbabAaBAbAaaBBbABbBBbaaAaAaBBbaBbabBbBABbaaBbAaabBABaBBbAAaaBABBAaaABAbbaaAaBaAAbAbbbbbaabBabaBbaabaAbaBaaa...

output:

386
327
309
141
424
175
186
273
45
498
99
262
478
149
424
444
49
267
233
388
359
310
203
81
498
12
97
295
400
351
352
407
310
471
291
479
448
203
267
60
223
458
421
391
5
470
212
253
99
281
167
451
154
86
299
434
370
255
383
207
258
310
487
380
6
368
235
137
334
141
50
128
29
478
448
223
466
345
407...

result:

ok 500000 lines

Test #5:

score: 0
Accepted
time: 563ms
memory: 92820kb

input:

10000
BaBbAAaaaaBAbbbbbaBbaaAbaaaabAaaaAAbabBAbaaBABaaabaAbBBaBBABAbabBAbaaAAaAABABbbbABBaBBaABbbAAbBabaAbaBBaAbabaaAAAabAbAABAabBbBaBaAaAbbBAAABbbabAaABABaBbaAABBbbBAABbbbAaABaAaaABAbbbABAabbaAaaBbbbBaBBbAaaabbaBbaaAbabBabaBaAAAbBAabbBAbabAAbbBBBbBAAaBBbBBAbaaaAbBaaBAAbbaAbbbBAbaAaaAbBBAaBabBaaaBab...

output:

-1
5219
4322
2614
7302
1876
-1
5584
2861
3586
4821
6579
6706
1605
7878
886
9218
293
167
7298
5146
6860
2921
8263
4330
9578
7472
6086
5537
4890
8285
58
9733
-1
3157
262
9533
6943
8285
2837
451
6494
7918
8912
2187
9832
4487
2077
871
210
951
1761
6892
4304
6634
9572
9544
5744
4015
7418
7804
5928
3611
8...

result:

ok 500000 lines

Test #6:

score: 0
Accepted
time: 617ms
memory: 97628kb

input:

100000
aabAbBbaBAaabbbbbaAAABaaabbBaBAAaBabbBAbBbbBbbbaaaABaaBaBbBABBBbabBAABbabbAaaaBBaAAbABaBABAABbBAbBAAAbaBaabbAAABaBAaaaBBbBbaBabAbBBaaabaaaaBbBaAaAbAbbBaABaabBbBaAAaAaaBbbAbbaaBBbbbaAaAabaBaAaaBaAAbbBabBaBAbAaabAbbbAbaAbBbaABABAaBBABAaABBBBABAaBAbbbaBbaAABBaAabaAbaAaabAAAbbbaBBbBaaaaAaaAABbBaa...

output:

35335
42708
80231
-1
52892
27828
25395
21105
26112
55093
16568
16170
-1
73256
-1
82801
58592
52120
48659
-1
-1
-1
92581
-1
67746
9463
50384
69443
71368
-1
62536
83524
71293
88216
83685
45630
5450
969
3140
19286
79236
80564
33058
44088
24142
-1
40385
68116
-1
20399
78247
52636
37514
-1
54565
44272
75...

result:

ok 500000 lines

Test #7:

score: -100
Runtime Error

input:

500000
AaAAaaAaaaAaaaaaAaAAAaaaaAAaAAAaaAAAaAaaaaAaAaaaAaAaAAaAAaAaaAaaAaAAAAAAAAAAAAaAaAAAaAaAAAAAaaaAaAAAaAaaaAaaAaaaaaaAaaaaAaAaaAAaAAaaAAAaAaaaaaaaAaAaAaAaaAAaaaAAaAaaAAAaaaaaaaAAaAAaAaaaaaAAaAaAaaAAaaaAAaaaAaAAaaaAaAaaAAAaaAAAaAaaaaaaaaaAaAaAaAAAaaAAAAaAaAAAAAAaAAAaAaaaaaaAAaAaaAAaAAAaaaAaAAaAA...

output:


result: