91492024-02-15 22:14:34111Periodikus Szavakcpp17Time limit exceeded 41/100570ms34420 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;
			if (g[i][j] >= MOD) {
				g[i][j] -= 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
1Accepted3ms1824 KiB
subtask214/14
2Accepted3ms2016 KiB
3Accepted3ms2256 KiB
4Accepted3ms2472 KiB
5Accepted3ms2820 KiB
6Accepted3ms2804 KiB
7Accepted3ms3004 KiB
8Accepted3ms2972 KiB
9Accepted3ms3156 KiB
10Accepted3ms3296 KiB
11Accepted3ms3376 KiB
12Accepted3ms3376 KiB
subtask327/27
13Accepted3ms3580 KiB
14Accepted3ms3580 KiB
15Accepted4ms3580 KiB
16Accepted3ms3612 KiB
17Accepted3ms4048 KiB
18Accepted3ms4008 KiB
19Accepted3ms4004 KiB
20Accepted3ms4008 KiB
21Accepted3ms4012 KiB
22Accepted4ms4112 KiB
subtask40/59
23Accepted21ms6492 KiB
24Accepted4ms4384 KiB
25Accepted18ms6120 KiB
26Accepted21ms6168 KiB
27Accepted8ms6168 KiB
28Accepted24ms6172 KiB
29Accepted26ms6424 KiB
30Accepted21ms6528 KiB
31Time limit exceeded510ms34388 KiB
32Accepted488ms34396 KiB
33Accepted52ms9476 KiB
34Accepted412ms30776 KiB
35Accepted483ms34404 KiB
36Accepted483ms34420 KiB
37Accepted86ms34392 KiB
38Time limit exceeded505ms34400 KiB
39Time limit exceeded566ms18572 KiB
40Time limit exceeded517ms34416 KiB
41Time limit exceeded570ms18572 KiB