QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650315 | #8079. Range Periodicity Query | lfyszy | TL | 0ms | 20516kb | C++14 | 1.8kb | 2024-10-18 14:35:00 | 2024-10-18 14:35:04 |
Judging History
answer
// problem:
// date:
#include <bits/stdc++.h>
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define SP << " " <<
#define fish signed
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 5e5 + 10;
int p[N], n, m;
string s[N];
bool st[2010][500];
void subtask1()
{
for(int k = 1; k <= n; k ++)
for(int i = 1; i <= m; i ++)
{
bool f = 1;
if(p[i] > (int)s[k].size()) f = 0;
for(int j = 1; j <= (int)s[k].size() - p[i]; j ++)
if(s[k][j - 1] != s[k][j + p[i] - 1]) {f = 0; break;}
st[k][i] = f;
}
int q; cin >> q;
while(q --)
{
int k, l, r; cin >> k >> l >> r;
int res = INF;
for(int i = l; i <= r; i ++) if(st[k][i]) chmin(res, p[i]);
cout << (res == INF ? -1 : res) << "\n";
}
}
void subtask2()
{
int q; cin >> q;
while(q --)
{
int k, l, r, res = INF; cin >> k >> l >> r;
for(int i = l; i <= r; i ++)
{
bool f = 0;
if(p[i] > (int)s[k].size()) continue;
for(int j = 1; j <= (int)s[k].size() - p[i]; j ++)
if(s[k][j - 1] != s[k][j + p[i] - 1]) {f = 1; break;}
if(!f) chmin(res, p[i]);
}
cout << (res == INF ? -1 : res) << "\n";
}
}
fish main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
string str; cin >> str;
for(int i = 1; i <= n; i ++)
{
if('a' <= str[i - 1] && str[i - 1] <= 'z') s[i] = str[i - 1] + s[i - 1];
else s[i] = s[i - 1] + char(str[i - 1] - 'A' + 'a');
// cerr << s[i] << "\n";
}
cin >> m;
for(int i = 1; i <= m; i ++) cin >> p[i];
if(n <= 1000 && m <= 3) subtask1();
else subtask2();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 20516kb
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...