QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650309 | #8079. Range Periodicity Query | ASnown | TL | 1ms | 5816kb | C++14 | 1.4kb | 2024-10-18 14:33:44 | 2024-10-18 14:33:45 |
Judging History
answer
// #define NDEBUG
#include<bits/stdc++.h>
#define file(F) freopen(#F".in","r",stdin),freopen(#F".out","w",stdout)
#define lowbit(x) ((x)&-(x))
#define ALL(x) (x).begin(),(x).end()
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define popcount(x) (__builtin_popcount((x)))
using namespace std;
using ll=long long;
using uint=uint32_t;
template<typename T>
inline bool Max(T &x,T y) { return std::less<T>()(x,y)&&(x=y,true); }
template<typename T>
inline bool Min(T &x,T y) { return std::less<T>()(y,x)&&(x=y,true); }
void Solve();
const int N = 5e5+55;
int n,m,Q;
int p[N];
string d;
int b[N];
int kmp(const string &s) {
int n=s.size();
vector<int> p(n);
for(int i=1,j=0;i<n;i++) {
while(j&&s[i]!=s[j]) j=p[j-1];
if(s[i]==s[j]) ++j;
p[i]=j;
}
return n-p.back();
}
signed main() {
#ifndef ONLINE_JUDGE
#endif
// file(period);
cin.tie(nullptr)->sync_with_stdio(false);
Solve();
}
void Solve() {
cin>>n>>d,d=' '+d;
string s;
for(int i=1;i<=n;i++) {
if(islower(d[i])) s=d[i]+s;
else s+=tolower(d[i]);
b[i]=kmp(s);
}
cin>>m;
for(int i=1;i<=m;i++) cin>>p[i];
cin>>Q;
while(Q--) {
int x,l,r; cin>>x>>l>>r;
int ans=0x3f3f3f3f;
for(int i=l;i<=r;i++)
if(p[i]<=x&&(p[i]%b[x]==0||p[i]>=x-x%b[x]))
Min(ans,p[i]);
printf("%d\n",ans==0x3f3f3f3f?-1:ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
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
Time Limit Exceeded
input:
200000 BAbBbBabBBbbABbbaBbaaabaBBAbBbBAAAAABBaBaAAabBAAbABaaBABAabAAAbabbAaBABAbabbAAAbbbbabBBAbbBaabBAAAbBBBbBbbAbbbBabbBABaBAaAAAbBbaABabBAbAAbBbbAbAbBaabAbBBbaaaaBaBbbABBBaaabBaBABAbBabBbbAABBbaBAbaBAbAAABABAbaabbaAAaBAbAbAbBBbaaaAaBaaABBbBAAaAAAaaABbbaAbAaBbaAaaababbaBbaAAAAAAabbBaAabbbaBBAAaABb...