QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442244 | #8079. Range Periodicity Query | rotcar07 | WA | 831ms | 94196kb | C++14 | 2.3kb | 2024-06-15 10:30:49 | 2024-06-15 15:03:21 |
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-06-15 10:30:49]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=5e5+5;
int n,m,q,L[maxn],R[maxn],ans[maxn];
vector<int> Q[maxn],P[maxn],E[maxn];
constexpr int inf=1e9;
int t[maxn<<2];
#define ls p<<1
#define rs p<<1|1
inline void pushup(int p){t[p]=min(t[ls],t[rs]);}
void build(int p,int l,int r){
t[p]=inf;
if(l==r) return;
int mid=l+r>>1;
build(ls,l,mid),build(rs,mid+1,r);
}
void modify(int p,int l,int r,int k,int x){
if(l==r) return t[p]=x,void();
int mid=l+r>>1;
if(k<=mid) modify(ls,l,mid,k,x);
else modify(rs,mid+1,r,k,x);
pushup(p);
}
int query(int p,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return t[p];
int mid=l+r>>1,res=inf;
if(ql<=mid) res=query(ls,l,mid,ql,qr);
if(qr>mid) res=min(res,query(rs,mid+1,r,ql,qr));
return res;
}
typedef unsigned long long ull;
constexpr ull mod=998244853;
const ull bas=random_device{}()%10000+200;
ull bs[maxn],hsh[maxn];
inline ull gethsh(int l,int r){
return (hsh[r]+mod-hsh[l-1]*bs[r-l+1]%mod)%mod;
}
string s,r,rv;int dt[maxn];
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// string name="suffix";freopen((name+".in").c_str(),"r",stdin);freopen((name+".out").c_str(),"w",stdout);
cin>>n>>s>>m;for(int i=bs[0]=1;i<=n;i++) bs[i]=bs[i-1]*bas%mod;
for(int i=1,x;i<=m;i++) cin>>x,P[x].push_back(i);cin>>q;
for(int i=1,x;i<=q;i++) cin>>x>>L[i]>>R[i],Q[x].push_back(i);
for(int i=1;i<n;i++) if(s[i]>='a'&&s[i]<='z') dt[1]++;
for(int i=1;i<n;i++) dt[i+1]=dt[i]-(s[i]>='a'&&s[i]<='z');
for(auto x:s) if(x>='a'&&x<='z') rv+=x;else r+=x+'a'-'A';
reverse(rv.begin(),rv.end());r=rv+r;
for(int i=0;i<n;i++) hsh[i+1]=(hsh[i]*bas+r[i])%mod;
for(int i=1;i<=n;i++){
int l=i,r=n;
while(l<r){
int mid=l+r+1>>1,d=dt[mid],L=mid-i;
if(gethsh(d+1,d+L)==gethsh(d+mid-L+1,d+mid)) l=mid;
else r=mid-1;
}E[l+1].push_back(i);
// cerr<<i<<" "<<l<<'\n';
}build(1,1,m);
for(int i=1;i<=n;i++){
for(auto x:P[i]) modify(1,1,m,x,i);
for(auto x:E[i])for(auto y:P[x]) modify(1,1,m,y,inf);
for(auto x:Q[i]) ans[x]=query(1,1,m,L[x],R[x]);
}
for(int i=1;i<=q;i++) cout<<(ans[i]==inf?-1:ans[i])<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 38788kb
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: 274ms
memory: 59396kb
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: 354ms
memory: 53204kb
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: 423ms
memory: 54056kb
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: 477ms
memory: 54968kb
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: 609ms
memory: 61828kb
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: 736ms
memory: 81228kb
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: 831ms
memory: 90624kb
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: 792ms
memory: 91448kb
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: 0
Accepted
time: 818ms
memory: 94196kb
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 398460 -1 -1 339034 -1 -1 -1 89916 -1 -1 -1 -1 -1 -1 -1 203747 160541 -1 -1 -1 -1 -1 -1 -1...
result:
ok 500000 lines
Test #11:
score: 0
Accepted
time: 792ms
memory: 90348kb
input:
500000 iPpiIpiPIPIPpipGagAPIpPIipPiIPIpPIiPIPpIPGAipPipipIiPpaIPgIpPIiPpIPIiPpiIPpGipiApiPIpiPpagIpPiIpiPIpPipLmMPlpipIPIiPpIPiGAPIpiPpIPagpIPipipIiPpIPiIPpiIPGAPpiIpPiIPpagpIPIiPIpipipPipiIpiPIpPiGApPIaPIgPIpipPiIPIpPiIpipPiIpPGAPipIPIipagPpIiPIpPIipPIPipiIpPipGipipAPagpiIPpIiPpIPIipipiPIPpiIpipaPI...
output:
44808 330831 40007 156828 89616 -1 44808 -1 156828 44808 22404 44808 44808 156828 156828 44808 745 22404 119492 37342 224040 -1 156828 40427 -1 44808 156828 -1 44808 44808 44808 44808 -1 156828 -1 22404 44808 -1 156828 22404 44808 37237 -1 44808 44808 44808 44808 44808 22404 44808 156828 22404 44808...
result:
ok 500000 lines
Test #12:
score: 0
Accepted
time: 789ms
memory: 90872kb
input:
500000 xEGXEGgexXEGgXEGexXEgexGXEGgexXEgGXexEGXEgexgexgeGXEGxgXEGXexgexgEGexXgeEGXxgexgexEgexgGexXgexgeExGXEGgXeExGgexXgEGeXxEGgexXgexgEexGXgEGexgexXgexgEGeXxgeEGXxgEexGXgexgEGeXxgexEgeGXxgexEGXgexgEexgeGxXEgGeXEGxgexgexgeXEGxXgexEGgXEGexXgeEGxgXexgexEGgXexEGgeXxEGXgexEgexGgXEGeXxgeExGXEGXgEexGgexgX...
output:
6 51880 51880 156658 51880 103760 103760 103760 58694 6 51880 51880 170203 155640 103760 160123 51880 6 271827 103760 51880 51880 259400 155640 84830 51880 259400 269226 103760 51880 82478 51880 51880 51880 76292 51880 103760 103760 103760 6 6 103760 51880 51880 51880 95600 103760 103760 51880 51880...
result:
ok 500000 lines
Test #13:
score: -100
Wrong Answer
time: 814ms
memory: 90880kb
input:
500000 qrbBRqrbQqrbBRQqrbBRqQBRrbqQBRrQbqBrRQbBRqQrbBqRrQBbRqrbqrbQBRqQBRQBrbRqQrbqBRrQBRbQBRqQrBRQBbRQqrbqrBbqrRQBRQbBRQBqrRQBbRQBqRQrBRQbBqrbqrRbqrbQBRqQBrRQBbRqQrBRQBRQBbRQBRQqBRQrBbRQBRQqrbBRqQBRQBrRQbBRqQrBbqRrQBbqRrbqrbqrQbqBRQBrbRqQBrbRqQrbqBrRbqrQBRQBbRqQBRQBrbqrRbQBqRQBRrQBRQBbqrbRqrQbBRQBq...
output:
105840 35280 25200 105840 35280 25200 25200 25200 5040 25200 5040 5973 5040 5040 5040 25200 25200 55440 25200 5040 5040 27 5040 5040 35280 5040 5040 5040 25200 231840 5040 5040 126000 67338 50400 236880 5040 5040 5040 196059 201600 5040 5040 100800 15120 25200 5040 5040 5040 95760 5040 25200 5040 25...
result:
wrong answer 3040th lines differ - expected: '145257', found: '140722'