#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
bool solve (vector<int> a, vector<int> b, int n) {
vector<int> pa(n), pb(n);
for (int i = 0; i < n; i++) pa[i] = pb[i] = i;
sort(all(pa), [&] (int i, int j) { return a[i] < a[j]; });
sort(all(pb), [&] (int i, int j) { return b[i] < b[j]; });
for (int i = 0; i < n; i++) {
if (pa[i] == pb[i]) {
if (i - 1 >= 0 && a[pa[i - 1]] > b[pb[i]]) continue;
if (i + 1 < n && a[pa[i]] > b[pb[i + 1]]) continue;
return 0;
}
if (a[pa[i]] < b[pb[i]]) return 0;
}
return 1;
}
const int mn = 5e5 + 5;
int a[mn], b[mn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
int q; cin >> q;
while (q--) {
int l, r; cin >> l >> r;
vector<int> vec_a, vec_b;
for (int i = l; i <= r; i++) {
vec_a.push_back(a[i]);
vec_b.push_back(b[i]);
}
cout << (solve(vec_a, vec_b, r - l + 1) ? "Yes" : "No") << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
2552 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2552 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2384 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
35 ms |
6608 KB |
Output is correct |
5 |
Correct |
31 ms |
6596 KB |
Output is correct |
6 |
Correct |
39 ms |
6504 KB |
Output is correct |
7 |
Correct |
30 ms |
6596 KB |
Output is correct |
8 |
Correct |
30 ms |
6592 KB |
Output is correct |
9 |
Correct |
30 ms |
6596 KB |
Output is correct |
10 |
Correct |
29 ms |
6596 KB |
Output is correct |
11 |
Correct |
37 ms |
6612 KB |
Output is correct |
12 |
Correct |
30 ms |
6596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
2552 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2552 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2384 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2516 KB |
Output is correct |
34 |
Correct |
1 ms |
2384 KB |
Output is correct |
35 |
Correct |
1 ms |
2384 KB |
Output is correct |
36 |
Correct |
1 ms |
2384 KB |
Output is correct |
37 |
Correct |
35 ms |
6608 KB |
Output is correct |
38 |
Correct |
31 ms |
6596 KB |
Output is correct |
39 |
Correct |
39 ms |
6504 KB |
Output is correct |
40 |
Correct |
30 ms |
6596 KB |
Output is correct |
41 |
Correct |
30 ms |
6592 KB |
Output is correct |
42 |
Correct |
30 ms |
6596 KB |
Output is correct |
43 |
Correct |
29 ms |
6596 KB |
Output is correct |
44 |
Correct |
37 ms |
6612 KB |
Output is correct |
45 |
Correct |
30 ms |
6596 KB |
Output is correct |
46 |
Correct |
62 ms |
4932 KB |
Output is correct |
47 |
Correct |
51 ms |
5484 KB |
Output is correct |
48 |
Correct |
20 ms |
4300 KB |
Output is correct |
49 |
Correct |
42 ms |
5600 KB |
Output is correct |
50 |
Correct |
76 ms |
5960 KB |
Output is correct |
51 |
Correct |
58 ms |
6080 KB |
Output is correct |
52 |
Correct |
9 ms |
3420 KB |
Output is correct |
53 |
Correct |
19 ms |
4444 KB |
Output is correct |
54 |
Correct |
180 ms |
6796 KB |
Output is correct |
55 |
Correct |
186 ms |
6808 KB |
Output is correct |
56 |
Correct |
73 ms |
6032 KB |
Output is correct |
57 |
Correct |
62 ms |
6088 KB |
Output is correct |
58 |
Correct |
60 ms |
6436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2520 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Execution timed out |
2594 ms |
5928 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2520 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Execution timed out |
2594 ms |
5928 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
2552 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2552 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2384 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2516 KB |
Output is correct |
34 |
Correct |
1 ms |
2384 KB |
Output is correct |
35 |
Correct |
1 ms |
2384 KB |
Output is correct |
36 |
Correct |
1 ms |
2384 KB |
Output is correct |
37 |
Correct |
35 ms |
6608 KB |
Output is correct |
38 |
Correct |
31 ms |
6596 KB |
Output is correct |
39 |
Correct |
39 ms |
6504 KB |
Output is correct |
40 |
Correct |
30 ms |
6596 KB |
Output is correct |
41 |
Correct |
30 ms |
6592 KB |
Output is correct |
42 |
Correct |
30 ms |
6596 KB |
Output is correct |
43 |
Correct |
29 ms |
6596 KB |
Output is correct |
44 |
Correct |
37 ms |
6612 KB |
Output is correct |
45 |
Correct |
30 ms |
6596 KB |
Output is correct |
46 |
Correct |
62 ms |
4932 KB |
Output is correct |
47 |
Correct |
51 ms |
5484 KB |
Output is correct |
48 |
Correct |
20 ms |
4300 KB |
Output is correct |
49 |
Correct |
42 ms |
5600 KB |
Output is correct |
50 |
Correct |
76 ms |
5960 KB |
Output is correct |
51 |
Correct |
58 ms |
6080 KB |
Output is correct |
52 |
Correct |
9 ms |
3420 KB |
Output is correct |
53 |
Correct |
19 ms |
4444 KB |
Output is correct |
54 |
Correct |
180 ms |
6796 KB |
Output is correct |
55 |
Correct |
186 ms |
6808 KB |
Output is correct |
56 |
Correct |
73 ms |
6032 KB |
Output is correct |
57 |
Correct |
62 ms |
6088 KB |
Output is correct |
58 |
Correct |
60 ms |
6436 KB |
Output is correct |
59 |
Correct |
1 ms |
2384 KB |
Output is correct |
60 |
Correct |
1 ms |
2520 KB |
Output is correct |
61 |
Correct |
1 ms |
2396 KB |
Output is correct |
62 |
Execution timed out |
2594 ms |
5928 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2552 KB |
Output is correct |
21 |
Correct |
1 ms |
2552 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
1 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
1 ms |
2552 KB |
Output is correct |
27 |
Correct |
1 ms |
2384 KB |
Output is correct |
28 |
Correct |
1 ms |
2384 KB |
Output is correct |
29 |
Correct |
1 ms |
2384 KB |
Output is correct |
30 |
Correct |
1 ms |
2384 KB |
Output is correct |
31 |
Correct |
1 ms |
2384 KB |
Output is correct |
32 |
Correct |
1 ms |
2384 KB |
Output is correct |
33 |
Correct |
1 ms |
2516 KB |
Output is correct |
34 |
Correct |
1 ms |
2384 KB |
Output is correct |
35 |
Correct |
1 ms |
2384 KB |
Output is correct |
36 |
Correct |
1 ms |
2384 KB |
Output is correct |
37 |
Correct |
35 ms |
6608 KB |
Output is correct |
38 |
Correct |
31 ms |
6596 KB |
Output is correct |
39 |
Correct |
39 ms |
6504 KB |
Output is correct |
40 |
Correct |
30 ms |
6596 KB |
Output is correct |
41 |
Correct |
30 ms |
6592 KB |
Output is correct |
42 |
Correct |
30 ms |
6596 KB |
Output is correct |
43 |
Correct |
29 ms |
6596 KB |
Output is correct |
44 |
Correct |
37 ms |
6612 KB |
Output is correct |
45 |
Correct |
30 ms |
6596 KB |
Output is correct |
46 |
Correct |
62 ms |
4932 KB |
Output is correct |
47 |
Correct |
51 ms |
5484 KB |
Output is correct |
48 |
Correct |
20 ms |
4300 KB |
Output is correct |
49 |
Correct |
42 ms |
5600 KB |
Output is correct |
50 |
Correct |
76 ms |
5960 KB |
Output is correct |
51 |
Correct |
58 ms |
6080 KB |
Output is correct |
52 |
Correct |
9 ms |
3420 KB |
Output is correct |
53 |
Correct |
19 ms |
4444 KB |
Output is correct |
54 |
Correct |
180 ms |
6796 KB |
Output is correct |
55 |
Correct |
186 ms |
6808 KB |
Output is correct |
56 |
Correct |
73 ms |
6032 KB |
Output is correct |
57 |
Correct |
62 ms |
6088 KB |
Output is correct |
58 |
Correct |
60 ms |
6436 KB |
Output is correct |
59 |
Correct |
1 ms |
2384 KB |
Output is correct |
60 |
Correct |
1 ms |
2520 KB |
Output is correct |
61 |
Correct |
1 ms |
2396 KB |
Output is correct |
62 |
Execution timed out |
2594 ms |
5928 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |