9148 | 2024-02-15 22:12:00 | 111 | Periodikus Szavak | cpp17 | Time limit exceeded 41/100 | 578ms | 35544 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define MOD 1000000007
#define BASE 256
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef CB
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int N;
string S;
cin >> N >> S;
vector<int> h(N + 1);
vector<int> p(N + 1);
vector<vector<int>> g(N + 1);
p[0] = 1;
for (int i = 1; i <= N; i++) {
h[i] = (h[i - 1] * BASE + S[i - 1]) % MOD;
p[i] = (p[i - 1] * BASE) % MOD;
g[i].resize(N / i + 1);
g[i][0] = 1;
for (int j = 1, k = p[i]; i * j <= N; j++, k = k * p[i] % MOD) {
g[i][j] = (g[i][j - 1] + k) % MOD;
}
}
int Q;
cin >> Q;
while (Q--) {
int l, r;
cin >> l >> r;
r++;
int ans = 0;
auto check = [&](int i) {
int x = ((h[l + i] - h[l] * p[i]) % MOD + MOD) % MOD;
int y = 0;
y += x * g[i][(r - l) / i - 1] % MOD;
y += h[l] * p[r - l];
y %= MOD;
return y == h[r];
};
if (check(1)) {
cout << "YES" << '\n';
continue;
}
for (int i = 2; i * i < r - l; i++) {
if ((r - l) % i) {
continue;
}
if (check(i) || check((r - l) / i)) {
ans = 1;
break;
}
}
cout << (ans ? "YES" : "NO") << '\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
subtask2 | 14/14 | ||||||
2 | Accepted | 3ms | 2020 KiB | ||||
3 | Accepted | 3ms | 2256 KiB | ||||
4 | Accepted | 3ms | 2336 KiB | ||||
5 | Accepted | 3ms | 2560 KiB | ||||
6 | Accepted | 3ms | 2756 KiB | ||||
7 | Accepted | 3ms | 2976 KiB | ||||
8 | Accepted | 3ms | 3104 KiB | ||||
9 | Accepted | 3ms | 3184 KiB | ||||
10 | Accepted | 3ms | 3548 KiB | ||||
11 | Accepted | 3ms | 3580 KiB | ||||
12 | Accepted | 3ms | 3708 KiB | ||||
subtask3 | 27/27 | ||||||
13 | Accepted | 3ms | 4036 KiB | ||||
14 | Accepted | 3ms | 3948 KiB | ||||
15 | Accepted | 4ms | 4084 KiB | ||||
16 | Accepted | 3ms | 4064 KiB | ||||
17 | Accepted | 4ms | 4472 KiB | ||||
18 | Accepted | 4ms | 4520 KiB | ||||
19 | Accepted | 4ms | 4516 KiB | ||||
20 | Accepted | 3ms | 4656 KiB | ||||
21 | Accepted | 3ms | 4744 KiB | ||||
22 | Accepted | 4ms | 4736 KiB | ||||
subtask4 | 0/59 | ||||||
23 | Accepted | 21ms | 7008 KiB | ||||
24 | Accepted | 4ms | 5000 KiB | ||||
25 | Accepted | 18ms | 6736 KiB | ||||
26 | Accepted | 21ms | 7060 KiB | ||||
27 | Accepted | 8ms | 7016 KiB | ||||
28 | Accepted | 24ms | 6956 KiB | ||||
29 | Accepted | 26ms | 7212 KiB | ||||
30 | Accepted | 21ms | 7424 KiB | ||||
31 | Accepted | 486ms | 35308 KiB | ||||
32 | Accepted | 486ms | 35288 KiB | ||||
33 | Accepted | 52ms | 10364 KiB | ||||
34 | Accepted | 405ms | 31656 KiB | ||||
35 | Accepted | 477ms | 35284 KiB | ||||
36 | Accepted | 500ms | 35276 KiB | ||||
37 | Accepted | 81ms | 35300 KiB | ||||
38 | Time limit exceeded | 501ms | 35396 KiB | ||||
39 | Time limit exceeded | 570ms | 19588 KiB | ||||
40 | Time limit exceeded | 517ms | 35544 KiB | ||||
41 | Time limit exceeded | 578ms | 19648 KiB |