91482024-02-15 22:12:00111Periodikus Szavakcpp17Time limit exceeded 41/100578ms35544 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
subtask214/14
2Accepted3ms2020 KiB
3Accepted3ms2256 KiB
4Accepted3ms2336 KiB
5Accepted3ms2560 KiB
6Accepted3ms2756 KiB
7Accepted3ms2976 KiB
8Accepted3ms3104 KiB
9Accepted3ms3184 KiB
10Accepted3ms3548 KiB
11Accepted3ms3580 KiB
12Accepted3ms3708 KiB
subtask327/27
13Accepted3ms4036 KiB
14Accepted3ms3948 KiB
15Accepted4ms4084 KiB
16Accepted3ms4064 KiB
17Accepted4ms4472 KiB
18Accepted4ms4520 KiB
19Accepted4ms4516 KiB
20Accepted3ms4656 KiB
21Accepted3ms4744 KiB
22Accepted4ms4736 KiB
subtask40/59
23Accepted21ms7008 KiB
24Accepted4ms5000 KiB
25Accepted18ms6736 KiB
26Accepted21ms7060 KiB
27Accepted8ms7016 KiB
28Accepted24ms6956 KiB
29Accepted26ms7212 KiB
30Accepted21ms7424 KiB
31Accepted486ms35308 KiB
32Accepted486ms35288 KiB
33Accepted52ms10364 KiB
34Accepted405ms31656 KiB
35Accepted477ms35284 KiB
36Accepted500ms35276 KiB
37Accepted81ms35300 KiB
38Time limit exceeded501ms35396 KiB
39Time limit exceeded570ms19588 KiB
40Time limit exceeded517ms35544 KiB
41Time limit exceeded578ms19648 KiB