/* There's someone in my head but it's not me */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 5e5 + 10, MOD = 1e9 + 7;
int gl[N], gr[N], ml[N], mr[N], nl[N], nr[N], lst[N], A[N], C[N], n, q; vector<int> B[N];
template <class func> struct node {
int x; node *lc, *rc; func cmp;
node() : x(0), lc(nullptr), rc(nullptr) {};
void build(int l = 1, int r = n) {
if (r - l < 2) return;
lc = new node<func>();
rc = new node<func>();
int md = (l + r) >> 1;
lc->build(l, md), rc->build(md, r);
}
void modify(int p, int y, int l = 1, int r = n) {
if (r - l < 2) { x = y; return; }
int md = (l + r) >> 1;
if (p < md) lc->modify(p, y, l, md);
else rc->modify(p, y, md, r);
x = cmp(lc->x, rc->x) ? lc->x : rc->x;
}
int get(int ql, int qr, int l = 1, int r = n) {
if (qr <= l || r <= ql) return cmp(1, 0) ? 0 : n + 1;
if (ql <= l && r <= qr) return x;
int md = (l + r) >> 1;
int a = lc->get(ql, qr, l, md), b = rc->get(ql, qr, md, r);
return cmp(a, b) ? a : b;
}
};
node<greater<>> *mx;
node<less<>> *mn;
int main() {
mx = new node<greater<>>();
mn = new node<less<>>();
scanf("%d", &n);
for (int i = 1; i < n; i++)
scanf("%d", &C[i]);
for (int i = 1, t, x; i <= n; i++) {
for (scanf("%d", &t); t; t--)
scanf("%d", &x), B[i].push_back(x);
}
mx->build(), mn->build();
for (int i = 1; i < n; i++) {
for (int &x : B[i]) lst[x] = i;
mn->modify(i, gl[i] = lst[C[i]]);
}
fill(lst, lst + N, n + 1);
for (int i = n - 1; i; i--) {
for (int &x : B[i + 1]) lst[x] = i + 1;
mx->modify(i, gr[i] = lst[C[i]]);
}
for (int i = n - 1; i; i--) {
for (nr[i] = i + 1; nr[i] < n && gl[i] <= gl[nr[i]]; nr[i] = nr[nr[i]]);
}
for (int i = 1; i < n; i++) {
for (nl[i] = i - 1; nl[i] && gr[i] >= gr[nl[i]]; nl[i] = nl[nl[i]]);
}
for (int i = 1; i <= n; i++) {
ml[i] = mr[i] = i;
for (;;) {
if (ml[i] > 1 && gr[ml[i] - 1] <= mr[i])
mr[i] = max(mr[i], mr[ml[i] - 1]), ml[i] = ml[ml[i] - 1];
else if (mr[i] < n && gl[mr[i]] >= ml[i])
mr[i]++;
else break;
}
}
for (scanf("%d", &q); q; q--) {
int x, y; scanf("%d%d", &x, &y);
if (x < y) printf(mr[x] >= y ? "YES\n" : "NO\n");
else printf(ml[x] <= y ? "YES\n" : "NO\n");
}
return 0;
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
50 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
52 | scanf("%d", &C[i]);
| ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:54:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
54 | for (scanf("%d", &t); t; t--)
| ~~~~~^~~~~~~~~~
long_mansion.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
55 | scanf("%d", &x), B[i].push_back(x);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:83:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
83 | for (scanf("%d", &q); q; q--) {
| ~~~~~^~~~~~~~~~
long_mansion.cpp:84:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
84 | int x, y; scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14560 KB |
Output is correct |
2 |
Correct |
13 ms |
14844 KB |
Output is correct |
3 |
Correct |
15 ms |
15308 KB |
Output is correct |
4 |
Correct |
13 ms |
14540 KB |
Output is correct |
5 |
Correct |
13 ms |
14540 KB |
Output is correct |
6 |
Correct |
13 ms |
14540 KB |
Output is correct |
7 |
Correct |
12 ms |
14540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14560 KB |
Output is correct |
2 |
Correct |
13 ms |
14844 KB |
Output is correct |
3 |
Correct |
15 ms |
15308 KB |
Output is correct |
4 |
Correct |
13 ms |
14540 KB |
Output is correct |
5 |
Correct |
13 ms |
14540 KB |
Output is correct |
6 |
Correct |
13 ms |
14540 KB |
Output is correct |
7 |
Correct |
12 ms |
14540 KB |
Output is correct |
8 |
Correct |
157 ms |
20388 KB |
Output is correct |
9 |
Correct |
142 ms |
20304 KB |
Output is correct |
10 |
Correct |
147 ms |
20928 KB |
Output is correct |
11 |
Correct |
153 ms |
21720 KB |
Output is correct |
12 |
Correct |
143 ms |
19784 KB |
Output is correct |
13 |
Correct |
150 ms |
20596 KB |
Output is correct |
14 |
Correct |
153 ms |
20700 KB |
Output is correct |
15 |
Correct |
145 ms |
20528 KB |
Output is correct |
16 |
Correct |
147 ms |
20420 KB |
Output is correct |
17 |
Correct |
147 ms |
20548 KB |
Output is correct |
18 |
Correct |
149 ms |
20560 KB |
Output is correct |
19 |
Correct |
194 ms |
20624 KB |
Output is correct |
20 |
Correct |
172 ms |
20536 KB |
Output is correct |
21 |
Correct |
146 ms |
20440 KB |
Output is correct |
22 |
Correct |
145 ms |
20548 KB |
Output is correct |
23 |
Correct |
147 ms |
20336 KB |
Output is correct |
24 |
Correct |
168 ms |
20480 KB |
Output is correct |
25 |
Correct |
155 ms |
20364 KB |
Output is correct |
26 |
Correct |
148 ms |
20344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
295 ms |
48296 KB |
Output is correct |
2 |
Correct |
287 ms |
48096 KB |
Output is correct |
3 |
Correct |
307 ms |
47880 KB |
Output is correct |
4 |
Correct |
292 ms |
48324 KB |
Output is correct |
5 |
Correct |
299 ms |
48200 KB |
Output is correct |
6 |
Correct |
253 ms |
47000 KB |
Output is correct |
7 |
Correct |
248 ms |
46676 KB |
Output is correct |
8 |
Correct |
246 ms |
46740 KB |
Output is correct |
9 |
Correct |
246 ms |
46788 KB |
Output is correct |
10 |
Correct |
243 ms |
46704 KB |
Output is correct |
11 |
Correct |
242 ms |
46660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14560 KB |
Output is correct |
2 |
Correct |
13 ms |
14844 KB |
Output is correct |
3 |
Correct |
15 ms |
15308 KB |
Output is correct |
4 |
Correct |
13 ms |
14540 KB |
Output is correct |
5 |
Correct |
13 ms |
14540 KB |
Output is correct |
6 |
Correct |
13 ms |
14540 KB |
Output is correct |
7 |
Correct |
12 ms |
14540 KB |
Output is correct |
8 |
Correct |
157 ms |
20388 KB |
Output is correct |
9 |
Correct |
142 ms |
20304 KB |
Output is correct |
10 |
Correct |
147 ms |
20928 KB |
Output is correct |
11 |
Correct |
153 ms |
21720 KB |
Output is correct |
12 |
Correct |
143 ms |
19784 KB |
Output is correct |
13 |
Correct |
150 ms |
20596 KB |
Output is correct |
14 |
Correct |
153 ms |
20700 KB |
Output is correct |
15 |
Correct |
145 ms |
20528 KB |
Output is correct |
16 |
Correct |
147 ms |
20420 KB |
Output is correct |
17 |
Correct |
147 ms |
20548 KB |
Output is correct |
18 |
Correct |
149 ms |
20560 KB |
Output is correct |
19 |
Correct |
194 ms |
20624 KB |
Output is correct |
20 |
Correct |
172 ms |
20536 KB |
Output is correct |
21 |
Correct |
146 ms |
20440 KB |
Output is correct |
22 |
Correct |
145 ms |
20548 KB |
Output is correct |
23 |
Correct |
147 ms |
20336 KB |
Output is correct |
24 |
Correct |
168 ms |
20480 KB |
Output is correct |
25 |
Correct |
155 ms |
20364 KB |
Output is correct |
26 |
Correct |
148 ms |
20344 KB |
Output is correct |
27 |
Correct |
295 ms |
48296 KB |
Output is correct |
28 |
Correct |
287 ms |
48096 KB |
Output is correct |
29 |
Correct |
307 ms |
47880 KB |
Output is correct |
30 |
Correct |
292 ms |
48324 KB |
Output is correct |
31 |
Correct |
299 ms |
48200 KB |
Output is correct |
32 |
Correct |
253 ms |
47000 KB |
Output is correct |
33 |
Correct |
248 ms |
46676 KB |
Output is correct |
34 |
Correct |
246 ms |
46740 KB |
Output is correct |
35 |
Correct |
246 ms |
46788 KB |
Output is correct |
36 |
Correct |
243 ms |
46704 KB |
Output is correct |
37 |
Correct |
242 ms |
46660 KB |
Output is correct |
38 |
Correct |
606 ms |
125824 KB |
Output is correct |
39 |
Correct |
597 ms |
150272 KB |
Output is correct |
40 |
Correct |
474 ms |
100096 KB |
Output is correct |
41 |
Correct |
590 ms |
148556 KB |
Output is correct |
42 |
Correct |
257 ms |
47908 KB |
Output is correct |
43 |
Correct |
332 ms |
47888 KB |
Output is correct |
44 |
Correct |
370 ms |
75076 KB |
Output is correct |
45 |
Correct |
381 ms |
75200 KB |
Output is correct |
46 |
Correct |
379 ms |
75504 KB |
Output is correct |
47 |
Correct |
254 ms |
47936 KB |
Output is correct |
48 |
Correct |
254 ms |
47784 KB |
Output is correct |
49 |
Correct |
409 ms |
75132 KB |
Output is correct |
50 |
Correct |
367 ms |
75204 KB |
Output is correct |
51 |
Correct |
398 ms |
75552 KB |
Output is correct |
52 |
Correct |
356 ms |
74020 KB |
Output is correct |
53 |
Correct |
433 ms |
100548 KB |
Output is correct |
54 |
Correct |
535 ms |
126772 KB |
Output is correct |
55 |
Correct |
426 ms |
100600 KB |
Output is correct |