-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11046.cpp
More file actions
41 lines (36 loc) · 764 Bytes
/
11046.cpp
File metadata and controls
41 lines (36 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int N; cin >> N;
N = N*2+1;
int str[N];
for (int i = 0; i <N; i++) {
if (i % 2) cin >> str[i];
else str[i] = -1;
}
int dp[N]; for (int i = 0; i < N; i++) dp[i] = 1;
int c = 0, r = 0;
for (int i = 0; i < N; i++) {
int radius = min(r - i, dp[c * 2 - i]);
while (i - radius >= 0 && i + radius < N && str[i - radius] == str[i + radius]) radius++;
radius--;
dp[i] = radius;
if (r <= i + radius) {
r = i + radius;
c = i;
}
}
int M; cin >> M;
while (M--) {
int s,e; cin >> s >> e;
int m = s+e;
cout << (dp[m-1] >= e-s) << '\n';
}
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
solve();
return 0;
}