9147 | 2024-02-15 22:09:57 | 111 | Periodikus Szavak | cpp17 | Time limit exceeded 41/100 | 579ms | 45512 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].reserve(8);
g[i].push_back(1);
for (int j = 1, k = p[i]; i * j <= N; j++, k = k * p[i] % MOD) {
g[i].push_back((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 | 2016 KiB | ||||
3 | Accepted | 3ms | 2240 KiB | ||||
4 | Accepted | 3ms | 2464 KiB | ||||
5 | Accepted | 3ms | 2672 KiB | ||||
6 | Accepted | 2ms | 2624 KiB | ||||
7 | Accepted | 3ms | 2640 KiB | ||||
8 | Accepted | 3ms | 2880 KiB | ||||
9 | Accepted | 3ms | 2968 KiB | ||||
10 | Accepted | 3ms | 3052 KiB | ||||
11 | Accepted | 3ms | 3052 KiB | ||||
12 | Accepted | 3ms | 2924 KiB | ||||
subtask3 | 27/27 | ||||||
13 | Accepted | 4ms | 3480 KiB | ||||
14 | Accepted | 3ms | 3404 KiB | ||||
15 | Accepted | 3ms | 3292 KiB | ||||
16 | Accepted | 3ms | 3024 KiB | ||||
17 | Accepted | 3ms | 3276 KiB | ||||
18 | Accepted | 4ms | 3300 KiB | ||||
19 | Accepted | 4ms | 3296 KiB | ||||
20 | Accepted | 3ms | 3496 KiB | ||||
21 | Accepted | 3ms | 3440 KiB | ||||
22 | Accepted | 4ms | 3440 KiB | ||||
subtask4 | 0/59 | ||||||
23 | Accepted | 21ms | 7136 KiB | ||||
24 | Accepted | 4ms | 3824 KiB | ||||
25 | Accepted | 18ms | 6504 KiB | ||||
26 | Accepted | 21ms | 7036 KiB | ||||
27 | Accepted | 8ms | 7028 KiB | ||||
28 | Accepted | 24ms | 7032 KiB | ||||
29 | Accepted | 27ms | 7284 KiB | ||||
30 | Accepted | 21ms | 7472 KiB | ||||
31 | Accepted | 488ms | 45512 KiB | ||||
32 | Accepted | 486ms | 45396 KiB | ||||
33 | Accepted | 52ms | 11152 KiB | ||||
34 | Accepted | 409ms | 40304 KiB | ||||
35 | Accepted | 486ms | 45456 KiB | ||||
36 | Accepted | 488ms | 45440 KiB | ||||
37 | Accepted | 81ms | 45432 KiB | ||||
38 | Time limit exceeded | 508ms | 45424 KiB | ||||
39 | Time limit exceeded | 566ms | 24016 KiB | ||||
40 | Time limit exceeded | 518ms | 45468 KiB | ||||
41 | Time limit exceeded | 579ms | 23992 KiB |