# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
125392 |
2019-07-05T07:33:37 Z |
조승현(#3064) |
Long Mansion (JOI17_long_mansion) |
C++14 |
|
515 ms |
62376 KB |
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define N_ 510000
#define pii pair<int,int>
int n, Q;
int C[N_], w[N_];
vector<int>G[N_], P[N_];
int LOK[N_], ROK[N_];
int L[N_], R[N_];
int Left[N_], Right[N_];
pii Go(int l, int r, int b, int e) {
while (1) {
if (r < e && Left[r] >= l)r++;
else if (l > b && Right[l - 1] <= r)l--;
else break;
}
return { l,r };
}
void Do(int b, int e) {
if (b == e) {
LOK[b] = ROK[e] = 1;
L[b] = R[b] = b;
return;
}
if (e == b + 1) {
LOK[b] = ROK[e] = 1;
L[b] = R[b] = b, L[e] = R[e] = e;
if (Left[b] == b) {
R[b] = e, ROK[b] = 1;
}
if (Right[b] == e) {
L[e] = b, LOK[e] = 1;
}
return;
}
int m = (b + e) >> 1;
Do(b, m);
Do(m, e);
int i, Mx = m, Mn = m;
for (i = m; i >= b; i--) {
if (!ROK[i])continue;
Mn = min(Mn, i);
int l = Mn, r = Mx;
pii tp = Go(l, r, b, e);
LOK[i] = ROK[i] = 0;
l = tp.first, r = tp.second;
L[i] = min(L[i], l);
R[i] = max(L[i], r);
if (tp.first == b)LOK[i] = 1;
if (tp.second == e)ROK[i] = 1;
Mn = tp.first;
Mx = tp.second;
}
Mx = Mn = m;
for (i = m; i <= e; i++) {
if (!LOK[i])continue;
Mx = max(Mx, i);
int l = Mn, r = Mx;
pii tp = Go(l, r, b, e);
LOK[i] = ROK[i] = 0;
l = tp.first, r = tp.second;
L[i] = min(L[i], l);
R[i] = max(L[i], r);
if (tp.first == b)LOK[i] = 1;
if (tp.second == e)ROK[i] = 1;
Mn = tp.first;
Mx = tp.second;
}
}
int AA[N_];
int main() {
int i, c, a;
scanf("%d", &n);
for (i = 1; i < n; i++) {
scanf("%d", &w[i]);
}
for (i = 1; i <= n; i++) {
scanf("%d", &c);
while (c--) {
scanf("%d", &a);
G[i].push_back(a);
P[a].push_back(i);
}
if (i != n) {
if (!P[w[i]].empty()) {
Left[i] = P[w[i]].back();
}
}
}
for (i = n; i >= 1; i--) {
for (auto &x : G[i])AA[x] = i;
if (i != 1) {
if (AA[w[i - 1]])Right[i - 1] = AA[w[i - 1]];
else Right[i - 1] = n + 1;
}
}
Do(1, n);
int Q;
scanf("%d", &Q);
while (Q--) {
int a, b;
scanf("%d%d", &a, &b);
if (R[a] >= b && L[a] <= b) {
puts("YES");
}
else puts("NO");
}
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
long_mansion.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &w[i]);
~~~~~^~~~~~~~~~~~~
long_mansion.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &c);
~~~~~^~~~~~~~~~
long_mansion.cpp:83:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
~~~~~^~~~~~~~~~
long_mansion.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q);
~~~~~^~~~~~~~~~
long_mansion.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
24568 KB |
Output is correct |
2 |
Correct |
28 ms |
24568 KB |
Output is correct |
3 |
Correct |
27 ms |
24696 KB |
Output is correct |
4 |
Correct |
27 ms |
24572 KB |
Output is correct |
5 |
Correct |
27 ms |
24440 KB |
Output is correct |
6 |
Correct |
27 ms |
24568 KB |
Output is correct |
7 |
Correct |
26 ms |
24568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
24568 KB |
Output is correct |
2 |
Correct |
28 ms |
24568 KB |
Output is correct |
3 |
Correct |
27 ms |
24696 KB |
Output is correct |
4 |
Correct |
27 ms |
24572 KB |
Output is correct |
5 |
Correct |
27 ms |
24440 KB |
Output is correct |
6 |
Correct |
27 ms |
24568 KB |
Output is correct |
7 |
Correct |
26 ms |
24568 KB |
Output is correct |
8 |
Correct |
153 ms |
25980 KB |
Output is correct |
9 |
Correct |
153 ms |
26072 KB |
Output is correct |
10 |
Correct |
155 ms |
26232 KB |
Output is correct |
11 |
Correct |
154 ms |
26572 KB |
Output is correct |
12 |
Correct |
158 ms |
26192 KB |
Output is correct |
13 |
Correct |
149 ms |
26232 KB |
Output is correct |
14 |
Correct |
153 ms |
26232 KB |
Output is correct |
15 |
Correct |
147 ms |
26268 KB |
Output is correct |
16 |
Correct |
142 ms |
26456 KB |
Output is correct |
17 |
Correct |
150 ms |
26232 KB |
Output is correct |
18 |
Correct |
150 ms |
26272 KB |
Output is correct |
19 |
Correct |
149 ms |
26232 KB |
Output is correct |
20 |
Correct |
145 ms |
26360 KB |
Output is correct |
21 |
Correct |
143 ms |
26416 KB |
Output is correct |
22 |
Correct |
148 ms |
26232 KB |
Output is correct |
23 |
Correct |
150 ms |
26204 KB |
Output is correct |
24 |
Correct |
150 ms |
26076 KB |
Output is correct |
25 |
Correct |
151 ms |
26136 KB |
Output is correct |
26 |
Correct |
151 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
34672 KB |
Output is correct |
2 |
Correct |
290 ms |
34296 KB |
Output is correct |
3 |
Correct |
293 ms |
34068 KB |
Output is correct |
4 |
Correct |
293 ms |
34424 KB |
Output is correct |
5 |
Correct |
294 ms |
34468 KB |
Output is correct |
6 |
Correct |
238 ms |
32888 KB |
Output is correct |
7 |
Correct |
232 ms |
33152 KB |
Output is correct |
8 |
Correct |
227 ms |
33340 KB |
Output is correct |
9 |
Correct |
229 ms |
33236 KB |
Output is correct |
10 |
Correct |
235 ms |
33240 KB |
Output is correct |
11 |
Correct |
226 ms |
33272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
24568 KB |
Output is correct |
2 |
Correct |
28 ms |
24568 KB |
Output is correct |
3 |
Correct |
27 ms |
24696 KB |
Output is correct |
4 |
Correct |
27 ms |
24572 KB |
Output is correct |
5 |
Correct |
27 ms |
24440 KB |
Output is correct |
6 |
Correct |
27 ms |
24568 KB |
Output is correct |
7 |
Correct |
26 ms |
24568 KB |
Output is correct |
8 |
Correct |
153 ms |
25980 KB |
Output is correct |
9 |
Correct |
153 ms |
26072 KB |
Output is correct |
10 |
Correct |
155 ms |
26232 KB |
Output is correct |
11 |
Correct |
154 ms |
26572 KB |
Output is correct |
12 |
Correct |
158 ms |
26192 KB |
Output is correct |
13 |
Correct |
149 ms |
26232 KB |
Output is correct |
14 |
Correct |
153 ms |
26232 KB |
Output is correct |
15 |
Correct |
147 ms |
26268 KB |
Output is correct |
16 |
Correct |
142 ms |
26456 KB |
Output is correct |
17 |
Correct |
150 ms |
26232 KB |
Output is correct |
18 |
Correct |
150 ms |
26272 KB |
Output is correct |
19 |
Correct |
149 ms |
26232 KB |
Output is correct |
20 |
Correct |
145 ms |
26360 KB |
Output is correct |
21 |
Correct |
143 ms |
26416 KB |
Output is correct |
22 |
Correct |
148 ms |
26232 KB |
Output is correct |
23 |
Correct |
150 ms |
26204 KB |
Output is correct |
24 |
Correct |
150 ms |
26076 KB |
Output is correct |
25 |
Correct |
151 ms |
26136 KB |
Output is correct |
26 |
Correct |
151 ms |
26104 KB |
Output is correct |
27 |
Correct |
292 ms |
34672 KB |
Output is correct |
28 |
Correct |
290 ms |
34296 KB |
Output is correct |
29 |
Correct |
293 ms |
34068 KB |
Output is correct |
30 |
Correct |
293 ms |
34424 KB |
Output is correct |
31 |
Correct |
294 ms |
34468 KB |
Output is correct |
32 |
Correct |
238 ms |
32888 KB |
Output is correct |
33 |
Correct |
232 ms |
33152 KB |
Output is correct |
34 |
Correct |
227 ms |
33340 KB |
Output is correct |
35 |
Correct |
229 ms |
33236 KB |
Output is correct |
36 |
Correct |
235 ms |
33240 KB |
Output is correct |
37 |
Correct |
226 ms |
33272 KB |
Output is correct |
38 |
Correct |
509 ms |
52444 KB |
Output is correct |
39 |
Correct |
466 ms |
57940 KB |
Output is correct |
40 |
Correct |
420 ms |
46420 KB |
Output is correct |
41 |
Correct |
515 ms |
57472 KB |
Output is correct |
42 |
Correct |
275 ms |
33784 KB |
Output is correct |
43 |
Correct |
274 ms |
33284 KB |
Output is correct |
44 |
Correct |
418 ms |
41512 KB |
Output is correct |
45 |
Correct |
418 ms |
41852 KB |
Output is correct |
46 |
Correct |
429 ms |
42360 KB |
Output is correct |
47 |
Correct |
297 ms |
34108 KB |
Output is correct |
48 |
Correct |
266 ms |
33528 KB |
Output is correct |
49 |
Correct |
435 ms |
40872 KB |
Output is correct |
50 |
Correct |
428 ms |
41308 KB |
Output is correct |
51 |
Correct |
438 ms |
43000 KB |
Output is correct |
52 |
Correct |
326 ms |
43896 KB |
Output is correct |
53 |
Correct |
394 ms |
52888 KB |
Output is correct |
54 |
Correct |
483 ms |
62376 KB |
Output is correct |
55 |
Correct |
403 ms |
52984 KB |
Output is correct |