QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#397696 | #8079. Range Periodicity Query | cwfxlh | WA | 1723ms | 109096kb | C++14 | 2.6kb | 2024-04-24 16:02:58 | 2024-04-24 16:02:59 |
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:02:58]
- 提交
answer
#include<bits/stdc++.h>
#define int long long
#define P 13331
#define MOD 998244353
using namespace std;
int n,m,q,l[500003],r[500003],k[500003],ans[500003],a[500003],hs[500003],fsp[500003];
int L[500003],R[500003];
pair<int,int>qq[500003];
string opS,S;
int Que[1200003],lft,rgt,mid,delwz[500003];
vector<int>lst[500003];
vector<int>lst2[500003];
int 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){
if(nowl==nowr){
val[now]=10000000;
return;
}
build(now*2,nowl,((nowl+nowr)>>1));
build(now*2+1,((nowl+nowr)>>1)+1,nowr);
val[now]=min(val[now*2],val[now*2+1]);
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));
}
signed main(){
ios::sync_with_stdio(false);
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]<='D')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]<='D')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;
}
delwz[i]=lft+1;
lst[delwz[i]].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:lst[i])modify(1,j,10000000,1,m);
for(auto j:lst2[i])modify(1,j,a[j],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: 3ms
memory: 33096kb
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: 295ms
memory: 62276kb
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: 520ms
memory: 79888kb
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: 682ms
memory: 81256kb
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: 755ms
memory: 83212kb
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: 1175ms
memory: 89748kb
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: 1202ms
memory: 101108kb
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: 0
Accepted
time: 1642ms
memory: 107220kb
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...
result:
ok 500000 lines
Test #9:
score: 0
Accepted
time: 1677ms
memory: 108284kb
input:
500000 cCCBAcaAbbbBAbAAAabaCCcbbaCAacABcaCBCBCBCaacCCBbcBacAaaAABBBaCbcccBcaAcaBCBcccbCcaBAbbCAcCbcacAaAbcCbcCAcaaaBabBCbCCaCbCAcAAbAaCbcCCACbCccCACcCcCbAcAbBaCCAbacBAcaBbAcCBcAcbacCCabCAacbCCbCCCBcacCaCbCacccaCbcBaaCCaACAaaabCAbBcAAAcCaCaBcaccaacAaacbbCacBBBCBaaCBACCAaaccbBaBCacabcBbCACCbaBaCaCbAbb...
output:
-1 -1 373736 135320 -1 -1 -1 -1 -1 -1 -1 -1 106473 295826 386781 382253 -1 -1 211227 -1 -1 435332 -1 487098 -1 -1 -1 322685 387263 -1 366267 299799 -1 -1 -1 63851 301486 426183 -1 -1 -1 158872 299489 -1 158501 -1 -1 -1 421755 -1 -1 -1 -1 -1 -1 -1 379236 -1 -1 162368 -1 20735 -1 379535 408080 43142 -...
result:
ok 500000 lines
Test #10:
score: -100
Wrong Answer
time: 1723ms
memory: 109096kb
input:
500000 CGLmxIQvAprgtdDDuZvZDwKvAyqsptLBKwehlQYMUAGNZYjIBwQJotGzdfdJefPNFsvQmsQMQHDThKCosCRLBfDPBmYrOzoPCOmRFKyCEwmCYZrZpzNeUuHsUBqpXrqKbmoNqsUAIGBCNFeHnXUeGaUAKLXrjtcHVKgdmNavqTnAqAIcqyujjfqPDbrQaYwiqKQNMQMCMjxcxVgHfoMdlIjsRbKBADzljmfNENfFOXjVCcUAmnqgcRKfIqCeQMXcqqTtgDSjYpDrKCbAIvpYqtxDCmniGfURGBNPg...
output:
-1 -1 -1 -1 153175 -1 -1 160471 8265 -1 -1 304616 -1 -1 457941 -1 136029 239352 -1 -1 248379 201699 -1 376599 218943 -1 -1 -1 -1 -1 283494 441809 -1 471567 -1 -1 -1 40751 -1 -1 181033 -1 -1 -1 -1 -1 -1 4025 -1 398462 -1 -1 339034 -1 -1 -1 89916 -1 -1 -1 -1 -1 -1 -1 203747 160541 -1 -1 -1 -1 -1 -1 -1...
result:
wrong answer 50th lines differ - expected: '398460', found: '398462'