#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 5e5+10;
int l[maxn], r[maxn];
int edge_sweep_l[maxn], edge_sweep_r[maxn];
vector<int> keys[maxn];
bool tem(int x, int y, int cor) {
// return 1 if there is some element with color 'cor' inside the open interval ]x, y[
auto it = upper_bound(keys[cor].begin(), keys[cor].end(), x);
return it != keys[cor].end() && *it < y;
}
struct MP {
vector<pair<int,int>> mp;
void add(int i, int val) {
while(mp.size() && mp.back().second >= val)
mp.pop_back();
mp.push_back({i, val});
}
int query(int x) { return (--lower_bound(mp.rbegin(), mp.rend(), pair<int,int>(x, -1)))->second; }
} mp;
int main() {
int n; scanf("%d", &n);
for(int i = 1; i < n; i++) {
int c; scanf("%d", &c);
edge_sweep_l[i] = edge_sweep_r[i+1] = c;
}
for(int i = 1; i <= n; i++) {
int a, b; scanf("%d", &b);
while(b--) {
scanf("%d", &a);
keys[a].push_back(i);
}
}
// for(i = {0, n-1}) -> defino l[i]
// for(i = {n-1, 0}) -> defino r[i] usando l[i], e também redefino l[i] overextending it
l[1] = 0, r[n] = n+1; // the color of the edges are defined from [1, n] so we'll never be able to open c[0] and c[n+1] since they're 0
int cnt = 0;
for(int i = 1; i <= n; i++) {
l[i] = i-1;
while(tem(l[i], i+1, edge_sweep_l[l[i]]))
l[i] = l[l[i]], assert(++cnt <= n);
}
for(int i = n; i >= 1; i--) {
r[i] = i+1;
bool foi = 1;
while(foi) {
foi = 0;
while(tem(l[i], r[i], edge_sweep_r[r[i]]))
r[i] = r[r[i]], foi = 1;
if(r[i] - i > 1)
l[i] = min(l[i], mp.query(r[i]));
while(tem(l[i], r[i], edge_sweep_l[l[i]]))
l[i] = l[l[i]];
}
mp.add(i, l[i]);
}
int q; scanf("%d", &q);
while(q--) {
int x, y; scanf("%d %d", &x, &y);
puts(y > l[x] && y < r[x] ? "YES" : "NO");
}
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:32:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | int c; scanf("%d", &c);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | int a, b; scanf("%d", &b);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | int q; scanf("%d", &q);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:73:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | int x, y; scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12116 KB |
Output is correct |
2 |
Correct |
10 ms |
12244 KB |
Output is correct |
3 |
Correct |
11 ms |
12288 KB |
Output is correct |
4 |
Correct |
9 ms |
12152 KB |
Output is correct |
5 |
Correct |
9 ms |
12172 KB |
Output is correct |
6 |
Correct |
11 ms |
12188 KB |
Output is correct |
7 |
Correct |
9 ms |
12188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12116 KB |
Output is correct |
2 |
Correct |
10 ms |
12244 KB |
Output is correct |
3 |
Correct |
11 ms |
12288 KB |
Output is correct |
4 |
Correct |
9 ms |
12152 KB |
Output is correct |
5 |
Correct |
9 ms |
12172 KB |
Output is correct |
6 |
Correct |
11 ms |
12188 KB |
Output is correct |
7 |
Correct |
9 ms |
12188 KB |
Output is correct |
8 |
Correct |
145 ms |
14600 KB |
Output is correct |
9 |
Correct |
120 ms |
14640 KB |
Output is correct |
10 |
Correct |
134 ms |
15000 KB |
Output is correct |
11 |
Correct |
122 ms |
15260 KB |
Output is correct |
12 |
Correct |
122 ms |
14600 KB |
Output is correct |
13 |
Correct |
131 ms |
14904 KB |
Output is correct |
14 |
Correct |
122 ms |
14812 KB |
Output is correct |
15 |
Correct |
125 ms |
14884 KB |
Output is correct |
16 |
Correct |
113 ms |
14868 KB |
Output is correct |
17 |
Correct |
121 ms |
14872 KB |
Output is correct |
18 |
Correct |
139 ms |
14840 KB |
Output is correct |
19 |
Correct |
121 ms |
14860 KB |
Output is correct |
20 |
Correct |
126 ms |
14796 KB |
Output is correct |
21 |
Correct |
117 ms |
14820 KB |
Output is correct |
22 |
Correct |
128 ms |
14760 KB |
Output is correct |
23 |
Correct |
119 ms |
14644 KB |
Output is correct |
24 |
Correct |
125 ms |
14664 KB |
Output is correct |
25 |
Correct |
125 ms |
14588 KB |
Output is correct |
26 |
Correct |
120 ms |
14572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
18048 KB |
Output is correct |
2 |
Correct |
226 ms |
18740 KB |
Output is correct |
3 |
Correct |
199 ms |
18744 KB |
Output is correct |
4 |
Correct |
214 ms |
18916 KB |
Output is correct |
5 |
Correct |
217 ms |
19028 KB |
Output is correct |
6 |
Correct |
183 ms |
18136 KB |
Output is correct |
7 |
Correct |
177 ms |
18332 KB |
Output is correct |
8 |
Correct |
164 ms |
18320 KB |
Output is correct |
9 |
Correct |
168 ms |
18336 KB |
Output is correct |
10 |
Correct |
157 ms |
18452 KB |
Output is correct |
11 |
Correct |
164 ms |
18300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12116 KB |
Output is correct |
2 |
Correct |
10 ms |
12244 KB |
Output is correct |
3 |
Correct |
11 ms |
12288 KB |
Output is correct |
4 |
Correct |
9 ms |
12152 KB |
Output is correct |
5 |
Correct |
9 ms |
12172 KB |
Output is correct |
6 |
Correct |
11 ms |
12188 KB |
Output is correct |
7 |
Correct |
9 ms |
12188 KB |
Output is correct |
8 |
Correct |
145 ms |
14600 KB |
Output is correct |
9 |
Correct |
120 ms |
14640 KB |
Output is correct |
10 |
Correct |
134 ms |
15000 KB |
Output is correct |
11 |
Correct |
122 ms |
15260 KB |
Output is correct |
12 |
Correct |
122 ms |
14600 KB |
Output is correct |
13 |
Correct |
131 ms |
14904 KB |
Output is correct |
14 |
Correct |
122 ms |
14812 KB |
Output is correct |
15 |
Correct |
125 ms |
14884 KB |
Output is correct |
16 |
Correct |
113 ms |
14868 KB |
Output is correct |
17 |
Correct |
121 ms |
14872 KB |
Output is correct |
18 |
Correct |
139 ms |
14840 KB |
Output is correct |
19 |
Correct |
121 ms |
14860 KB |
Output is correct |
20 |
Correct |
126 ms |
14796 KB |
Output is correct |
21 |
Correct |
117 ms |
14820 KB |
Output is correct |
22 |
Correct |
128 ms |
14760 KB |
Output is correct |
23 |
Correct |
119 ms |
14644 KB |
Output is correct |
24 |
Correct |
125 ms |
14664 KB |
Output is correct |
25 |
Correct |
125 ms |
14588 KB |
Output is correct |
26 |
Correct |
120 ms |
14572 KB |
Output is correct |
27 |
Correct |
215 ms |
18048 KB |
Output is correct |
28 |
Correct |
226 ms |
18740 KB |
Output is correct |
29 |
Correct |
199 ms |
18744 KB |
Output is correct |
30 |
Correct |
214 ms |
18916 KB |
Output is correct |
31 |
Correct |
217 ms |
19028 KB |
Output is correct |
32 |
Correct |
183 ms |
18136 KB |
Output is correct |
33 |
Correct |
177 ms |
18332 KB |
Output is correct |
34 |
Correct |
164 ms |
18320 KB |
Output is correct |
35 |
Correct |
168 ms |
18336 KB |
Output is correct |
36 |
Correct |
157 ms |
18452 KB |
Output is correct |
37 |
Correct |
164 ms |
18300 KB |
Output is correct |
38 |
Correct |
290 ms |
24368 KB |
Output is correct |
39 |
Correct |
314 ms |
25820 KB |
Output is correct |
40 |
Correct |
274 ms |
22416 KB |
Output is correct |
41 |
Correct |
395 ms |
29508 KB |
Output is correct |
42 |
Correct |
189 ms |
24300 KB |
Output is correct |
43 |
Correct |
216 ms |
24296 KB |
Output is correct |
44 |
Correct |
260 ms |
27948 KB |
Output is correct |
45 |
Correct |
303 ms |
27856 KB |
Output is correct |
46 |
Correct |
282 ms |
28008 KB |
Output is correct |
47 |
Correct |
196 ms |
24516 KB |
Output is correct |
48 |
Correct |
176 ms |
24016 KB |
Output is correct |
49 |
Correct |
282 ms |
26996 KB |
Output is correct |
50 |
Correct |
260 ms |
27336 KB |
Output is correct |
51 |
Correct |
299 ms |
27768 KB |
Output is correct |
52 |
Correct |
218 ms |
31836 KB |
Output is correct |
53 |
Correct |
271 ms |
37988 KB |
Output is correct |
54 |
Correct |
296 ms |
44552 KB |
Output is correct |
55 |
Correct |
256 ms |
38220 KB |
Output is correct |