91472024-02-15 22:09:57111Periodikus Szavakcpp17Time limit exceeded 41/100579ms45512 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
subtask214/14
2Accepted3ms2016 KiB
3Accepted3ms2240 KiB
4Accepted3ms2464 KiB
5Accepted3ms2672 KiB
6Accepted2ms2624 KiB
7Accepted3ms2640 KiB
8Accepted3ms2880 KiB
9Accepted3ms2968 KiB
10Accepted3ms3052 KiB
11Accepted3ms3052 KiB
12Accepted3ms2924 KiB
subtask327/27
13Accepted4ms3480 KiB
14Accepted3ms3404 KiB
15Accepted3ms3292 KiB
16Accepted3ms3024 KiB
17Accepted3ms3276 KiB
18Accepted4ms3300 KiB
19Accepted4ms3296 KiB
20Accepted3ms3496 KiB
21Accepted3ms3440 KiB
22Accepted4ms3440 KiB
subtask40/59
23Accepted21ms7136 KiB
24Accepted4ms3824 KiB
25Accepted18ms6504 KiB
26Accepted21ms7036 KiB
27Accepted8ms7028 KiB
28Accepted24ms7032 KiB
29Accepted27ms7284 KiB
30Accepted21ms7472 KiB
31Accepted488ms45512 KiB
32Accepted486ms45396 KiB
33Accepted52ms11152 KiB
34Accepted409ms40304 KiB
35Accepted486ms45456 KiB
36Accepted488ms45440 KiB
37Accepted81ms45432 KiB
38Time limit exceeded508ms45424 KiB
39Time limit exceeded566ms24016 KiB
40Time limit exceeded518ms45468 KiB
41Time limit exceeded579ms23992 KiB