QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#397734 | #8079. Range Periodicity Query | cwfxlh | TL | 1443ms | 74780kb | C++14 | 2.5kb | 2024-04-24 16:23:17 | 2024-04-24 16:23:19 |
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 16:23:17]
- 提交
answer
#include<bits/stdc++.h>
#define ll long long
#define P 114517
#define MOD 1000000007
using namespace std;
int n,m,q,l[500003],r[500003],k[500003],ans[500003],a[500003];
ll fsp[500003],hs[500003];
int L[500003],R[500003];
pair<int,int>qq[500003];
string opS,S;
int Que[1200003],lft,rgt,mid;
vector<int>lst[500003];
vector<int>lst2[500003];
ll geths(int l,int r){return (((hs[r]-hs[l-1]*fsp[r-l+1])%MOD)+MOD)%MOD;}
int val[4000003];
void build(int now,int nowl,int nowr){
val[now]=10000000;
if(nowl==nowr)return;
build(now*2,nowl,((nowl+nowr)>>1));
build(now*2+1,((nowl+nowr)>>1)+1,nowr);
return;
}
void modify(int now,int wz,int v,int nowl,int nowr){
if(nowl==nowr){
val[now]=v;
return;
}
if(wz<=((nowl+nowr)>>1))modify(now*2,wz,v,nowl,((nowl+nowr)>>1));
else modify(now*2+1,wz,v,((nowl+nowr)>>1)+1,nowr);
val[now]=min(val[now*2],val[now*2+1]);
return;
}
int Query(int now,int ql,int qr,int nowl,int nowr){
if(nowl>=ql&&nowr<=qr)return val[now];
if(qr<=((nowl+nowr)>>1))return Query(now*2,ql,qr,nowl,((nowl+nowr)>>1));
if(ql>((nowl+nowr)>>1))return Query(now*2+1,ql,qr,((nowl+nowr)>>1)+1,nowr);
return min(Query(now*2,ql,qr,nowl,((nowl+nowr)>>1)),Query(now*2+1,ql,qr,((nowl+nowr)>>1)+1,nowr));
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
fsp[0]=1;
for(int i=1;i<=500000;i++)fsp[i]=fsp[i-1]*P%MOD;
cin>>n>>opS;
lft=700000;
rgt=lft-1;
for(int i=1;i<=n;i++){
if(opS[i-1]>='A'&&opS[i-1]<='Z')Que[++rgt]=opS[i-1]-'A'+'a';
else Que[--lft]=opS[i-1];
}
for(int i=lft;i<=rgt;i++)S+=(char)(Que[i]);
for(int i=1;i<=n;i++)hs[i]=(hs[i-1]*P+S[i-1])%MOD;
L[0]=700000-lft+1;
R[0]=699999-lft+1;
for(int i=1;i<=n;i++){
L[i]=L[i-1];R[i]=R[i-1];
if(opS[i-1]>='A'&&opS[i-1]<='Z')R[i]++;
else L[i]--;
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>a[i];
lft=a[i];
rgt=n;
while(lft<rgt){
mid=((lft+rgt)>>1)+1;
if(geths(L[mid],R[mid]-a[i])==geths(L[mid]+a[i],R[mid]))lft=mid;
else rgt=mid-1;
}
lst[lft+1].emplace_back(i);
lst2[a[i]].emplace_back(i);
}
build(1,1,m);
cin>>q;
for(int i=1;i<=q;i++)cin>>k[i]>>l[i]>>r[i];
for(int i=1;i<=q;i++)qq[i]=make_pair(k[i],i);
sort(qq+1,qq+q+1);
for(int i=1,j=0;i<=n;i++){
for(auto j:lst2[i])modify(1,j,a[j],1,m);
for(auto j:lst[i])modify(1,j,10000000,1,m);
while(j+1<=q&&qq[j+1].first==i){
j++;
ans[qq[j].second]=Query(1,l[qq[j].second],r[qq[j].second],1,m);
}
}
for(int i=1;i<=q;i++){
if(ans[i]==10000000)cout<<-1<<endl;
else cout<<ans[i]<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 48644kb
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: 310ms
memory: 56760kb
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: 475ms
memory: 62556kb
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: 611ms
memory: 63376kb
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: 700ms
memory: 66640kb
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: 1099ms
memory: 68204kb
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: 0
Accepted
time: 1443ms
memory: 74780kb
input:
500000 AaAAaaAaaaAaaaaaAaAAAaaaaAAaAAAaaAAAaAaaaaAaAaaaAaAaAAaAAaAaaAaaAaAAAAAAAAAAAAaAaAAAaAaAAAAAaaaAaAAAaAaaaAaaAaaaaaaAaaaaAaAaaAAaAAaaAAAaAaaaaaaaAaAaAaAaaAAaaaAAaAaaAAAaaaaaaaAAaAAaAaaaaaAAaAaAaaAAaaaAAaaaAaAAaaaAaAaaAAAaaAAAaAaaaaaaaaaAaAaAaAAAaaAAAAaAaAAAAAAaAAAaAaaaaaaAAaAaaAAaAAAaaaAaAAaAA...
output:
3 13 3 4 3 3 6 3 6 131 3 3 6 4 33 5 9 3 195 105 77 4 3 3 3 3 3 4 3 3 4 3 4 3 3 3 3 4 3 3 4 4 4 4 4 3 9 3 3 23 33 3 4 3 3 3 3 4 4 3 4 4 4 3 5 1 3 5 3 74 3 23 5 3 3 4 3 3 3 3 3 6 4 3 4 3 4 4 3 4 3 3 4 7 4 3 3 4 3 13 3 4 1 6 3 5 3 3 4 4 20 4 532 4 3 3 3 6 97 4 6 3 3 4 3 4 6 3 3 3 3 3 3 4 7 3 6 4 4 4 3 ...
result:
ok 500000 lines
Test #8:
score: -100
Time Limit Exceeded
input:
500000 BbBabaaAABbABbaAABaaAabBBABbBBBAbaAbbABAaBbbAAabAaBaabBbaABAbaAbBabbaaaaaaaaBBbbBabaaAAbaAABaAAAaAaAbbbaaAaaAaaABAAAAAbbbABaBBbBAAaAAaBbABbBaaBabaAAaBAABaAaaBBbaBaBaBaaAbBAbAaABbBaaAAAAAabBAABaaAbbBaBAAbBBaBaabBaBBAbAbaaaaAbBbaAbbaAaABBaaAbAaaBABABBaAbaBbAAbaAAbaBAbAAaabBbAaabABAaBBBAbBbbBABa...
output:
-1 125970 -1 -1 -1 435323 -1 425031 252960 236797 -1 -1 -1 334816 -1 -1 319448 234360 344601 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 38745 -1 379427 -1 325294 -1 -1 -1 365248 387079 -1 492283 346128 -1 -1 -1 356064 -1 -1 321398 -1 -1 13515 -1 338767 461122 -1 436442 -1 309126 -1 207537 -1 -1 -1 -1 381656 1079...