# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
125366 |
2019-07-05T07:04:12 Z |
이온조(#3059) |
Long Mansion (JOI17_long_mansion) |
C++14 |
|
778 ms |
108960 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
struct minseg {
vector<int> T;
void init(vector<int> &A, int idx, int s, int e) {
if(s == e) {
T[idx] = A[s];
return;
}
int m = s+e >> 1;
init(A, idx*2, s, m);
init(A, idx*2+1, m+1, e);
T[idx] = min(T[idx*2], T[idx*2+1]);
}
// 구간 [l, r]에서 v 이하이면서 가장 오른쪽에 있는 원소 위치 리턴
int find(int idx, int s, int e, int l, int r, int v) {
if(r < s || e < l || T[idx] > v) return -1;
if(s == e) return s;
int m = s+e >> 1;
int tmp = find(idx*2+1, m+1, e, l, r, v);
if(tmp != -1) return tmp;
return find(idx*2, s, m, l, r, v);
}
minseg(int sz) {
T.resize(sz*4);
}
};
struct maxseg {
vector<int> T;
void init(vector<int> &A, int idx, int s, int e) {
if(s == e) {
T[idx] = A[s];
return;
}
int m = s+e >> 1;
init(A, idx*2, s, m);
init(A, idx*2+1, m+1, e);
T[idx] = max(T[idx*2], T[idx*2+1]);
}
// 구간 [l, r]에서 v 이상이면서 가장 왼쪽에 있는 원소 위치 리턴
int find(int idx, int s, int e, int l, int r, int v) {
if(r < s || e < l || T[idx] < v) return -1;
if(s == e) return s;
int m = s+e >> 1;
int tmp = find(idx*2, s, m, l, r, v);
if(tmp != -1) return tmp;
return find(idx*2+1, m+1, e, l, r, v);
}
maxseg(int sz) {
T.resize(sz*4);
}
};
int LM[500009], RM[500009];
int C[500009], B[500009], L[500009], R[500009], LE[500009], RE[500009];
vector<int> A[500009], P[500009];
int main() {
int N; scanf("%d",&N);
for(int i=1; i<N; i++) scanf("%d", &C[i]);
for(int i=1; i<=N; i++) P[i].push_back(0);
for(int i=1; i<=N; i++) {
scanf("%d",&B[i]);
for(int j=0; j<B[i]; j++) {
int foo; scanf("%d",&foo);
P[foo].push_back(i);
A[i].push_back(foo);
}
}
for(int i=1; i<=N; i++) P[i].push_back(N+1);
R[0] = N+1; L[N] = 0;
for(int i=1; i<N; i++) {
L[i] = *(--upper_bound(P[C[i]].begin(), P[C[i]].end(), i));
R[i] = *upper_bound(P[C[i]].begin(), P[C[i]].end(), i);
}
minseg LG(N+1); maxseg RG(N+1);
vector<int> LS = {-1}, RS;
for(int i=1; i<=N; i++) LS.push_back(L[i]);
for(int i=0; i<N; i++) RS.push_back(R[i]);
LG.init(LS, 1, 1, N); RG.init(RS, 1, 0, N-1);
for(int i=0; i<N; i++) {
int s = i+1, e = LG.find(1, 1, N, i+1, R[i]-1, i);
// printf("LEFT INTERVAL: [%d, %d]\n", s, e);
LE[s] = e;
}
for(int i=1; i<=N; i++) {
int s = RG.find(1, 0, N-1, L[i], i-1, i+1) + 1, e = i;
// printf("RIGHT INTERVAL: [%d, %d]\n", s, e);
RE[e] = s;
}
for(int i=1; i<=N; i++) LM[i] = 0, RM[i] = N+1;
priority_queue<pii> LPQ, RPQ;
for(int i=1; i<=N; i++) {
while(LPQ.size() && LPQ.top().second < i) LPQ.pop();
if(LE[i] > 0) LPQ.push({i, LE[i]});
if(LPQ.size()) LM[i] = LPQ.top().first;
}
for(int i=N; i>=1; i--) {
while(RPQ.size() && i < RPQ.top().second) RPQ.pop();
if(RE[i] > 0) RPQ.push({-i, RE[i]});
if(RPQ.size()) RM[i] = -RPQ.top().first;
}
for(int i=1; i<=N; i++) {
// printf("i: %d, LM: %d, RM: %d\n", i, LM[i], RM[i]);
}
int Q; scanf("%d",&Q);
while(Q--) {
int X, Y; scanf("%d%d",&X,&Y);
if(LM[X] <= Y && Y <= RM[X]) puts("YES");
else puts("NO");
}
return 0;
}
Compilation message
long_mansion.cpp: In member function 'void minseg::init(std::vector<int>&, int, int, int)':
long_mansion.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s+e >> 1;
~^~
long_mansion.cpp: In member function 'int minseg::find(int, int, int, int, int, int)':
long_mansion.cpp:22:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s+e >> 1;
~^~
long_mansion.cpp: In member function 'void maxseg::init(std::vector<int>&, int, int, int)':
long_mansion.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s+e >> 1;
~^~
long_mansion.cpp: In member function 'int maxseg::find(int, int, int, int, int, int)':
long_mansion.cpp:48:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = s+e >> 1;
~^~
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int N; scanf("%d",&N);
~~~~~^~~~~~~~~
long_mansion.cpp:64:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<N; i++) scanf("%d", &C[i]);
~~~~~^~~~~~~~~~~~~
long_mansion.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&B[i]);
~~~~~^~~~~~~~~~~~
long_mansion.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int foo; scanf("%d",&foo);
~~~~~^~~~~~~~~~~
long_mansion.cpp:115:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int Q; scanf("%d",&Q);
~~~~~^~~~~~~~~
long_mansion.cpp:117:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int X, Y; scanf("%d%d",&X,&Y);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
24312 KB |
Output is correct |
2 |
Correct |
28 ms |
24356 KB |
Output is correct |
3 |
Correct |
29 ms |
24612 KB |
Output is correct |
4 |
Correct |
27 ms |
24272 KB |
Output is correct |
5 |
Correct |
27 ms |
24204 KB |
Output is correct |
6 |
Correct |
27 ms |
24172 KB |
Output is correct |
7 |
Correct |
26 ms |
24312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
24312 KB |
Output is correct |
2 |
Correct |
28 ms |
24356 KB |
Output is correct |
3 |
Correct |
29 ms |
24612 KB |
Output is correct |
4 |
Correct |
27 ms |
24272 KB |
Output is correct |
5 |
Correct |
27 ms |
24204 KB |
Output is correct |
6 |
Correct |
27 ms |
24172 KB |
Output is correct |
7 |
Correct |
26 ms |
24312 KB |
Output is correct |
8 |
Correct |
156 ms |
30236 KB |
Output is correct |
9 |
Correct |
157 ms |
30080 KB |
Output is correct |
10 |
Correct |
159 ms |
30572 KB |
Output is correct |
11 |
Correct |
158 ms |
31096 KB |
Output is correct |
12 |
Correct |
145 ms |
29536 KB |
Output is correct |
13 |
Correct |
154 ms |
30264 KB |
Output is correct |
14 |
Correct |
151 ms |
30264 KB |
Output is correct |
15 |
Correct |
150 ms |
30396 KB |
Output is correct |
16 |
Correct |
153 ms |
30024 KB |
Output is correct |
17 |
Correct |
150 ms |
30200 KB |
Output is correct |
18 |
Correct |
152 ms |
30228 KB |
Output is correct |
19 |
Correct |
149 ms |
30200 KB |
Output is correct |
20 |
Correct |
151 ms |
30260 KB |
Output is correct |
21 |
Correct |
146 ms |
29996 KB |
Output is correct |
22 |
Correct |
149 ms |
30096 KB |
Output is correct |
23 |
Correct |
151 ms |
30004 KB |
Output is correct |
24 |
Correct |
151 ms |
30012 KB |
Output is correct |
25 |
Correct |
152 ms |
30064 KB |
Output is correct |
26 |
Correct |
152 ms |
30072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
47968 KB |
Output is correct |
2 |
Correct |
333 ms |
47400 KB |
Output is correct |
3 |
Correct |
326 ms |
47224 KB |
Output is correct |
4 |
Correct |
341 ms |
47632 KB |
Output is correct |
5 |
Correct |
335 ms |
47684 KB |
Output is correct |
6 |
Correct |
282 ms |
46484 KB |
Output is correct |
7 |
Correct |
269 ms |
46196 KB |
Output is correct |
8 |
Correct |
270 ms |
46164 KB |
Output is correct |
9 |
Correct |
276 ms |
46320 KB |
Output is correct |
10 |
Correct |
266 ms |
46296 KB |
Output is correct |
11 |
Correct |
268 ms |
46256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
24312 KB |
Output is correct |
2 |
Correct |
28 ms |
24356 KB |
Output is correct |
3 |
Correct |
29 ms |
24612 KB |
Output is correct |
4 |
Correct |
27 ms |
24272 KB |
Output is correct |
5 |
Correct |
27 ms |
24204 KB |
Output is correct |
6 |
Correct |
27 ms |
24172 KB |
Output is correct |
7 |
Correct |
26 ms |
24312 KB |
Output is correct |
8 |
Correct |
156 ms |
30236 KB |
Output is correct |
9 |
Correct |
157 ms |
30080 KB |
Output is correct |
10 |
Correct |
159 ms |
30572 KB |
Output is correct |
11 |
Correct |
158 ms |
31096 KB |
Output is correct |
12 |
Correct |
145 ms |
29536 KB |
Output is correct |
13 |
Correct |
154 ms |
30264 KB |
Output is correct |
14 |
Correct |
151 ms |
30264 KB |
Output is correct |
15 |
Correct |
150 ms |
30396 KB |
Output is correct |
16 |
Correct |
153 ms |
30024 KB |
Output is correct |
17 |
Correct |
150 ms |
30200 KB |
Output is correct |
18 |
Correct |
152 ms |
30228 KB |
Output is correct |
19 |
Correct |
149 ms |
30200 KB |
Output is correct |
20 |
Correct |
151 ms |
30260 KB |
Output is correct |
21 |
Correct |
146 ms |
29996 KB |
Output is correct |
22 |
Correct |
149 ms |
30096 KB |
Output is correct |
23 |
Correct |
151 ms |
30004 KB |
Output is correct |
24 |
Correct |
151 ms |
30012 KB |
Output is correct |
25 |
Correct |
152 ms |
30064 KB |
Output is correct |
26 |
Correct |
152 ms |
30072 KB |
Output is correct |
27 |
Correct |
340 ms |
47968 KB |
Output is correct |
28 |
Correct |
333 ms |
47400 KB |
Output is correct |
29 |
Correct |
326 ms |
47224 KB |
Output is correct |
30 |
Correct |
341 ms |
47632 KB |
Output is correct |
31 |
Correct |
335 ms |
47684 KB |
Output is correct |
32 |
Correct |
282 ms |
46484 KB |
Output is correct |
33 |
Correct |
269 ms |
46196 KB |
Output is correct |
34 |
Correct |
270 ms |
46164 KB |
Output is correct |
35 |
Correct |
276 ms |
46320 KB |
Output is correct |
36 |
Correct |
266 ms |
46296 KB |
Output is correct |
37 |
Correct |
268 ms |
46256 KB |
Output is correct |
38 |
Correct |
754 ms |
94548 KB |
Output is correct |
39 |
Correct |
778 ms |
108960 KB |
Output is correct |
40 |
Correct |
604 ms |
79544 KB |
Output is correct |
41 |
Correct |
688 ms |
100784 KB |
Output is correct |
42 |
Correct |
321 ms |
46920 KB |
Output is correct |
43 |
Correct |
302 ms |
47248 KB |
Output is correct |
44 |
Correct |
499 ms |
61280 KB |
Output is correct |
45 |
Correct |
511 ms |
61204 KB |
Output is correct |
46 |
Correct |
508 ms |
60880 KB |
Output is correct |
47 |
Correct |
317 ms |
47228 KB |
Output is correct |
48 |
Correct |
344 ms |
47500 KB |
Output is correct |
49 |
Correct |
472 ms |
61712 KB |
Output is correct |
50 |
Correct |
481 ms |
61228 KB |
Output is correct |
51 |
Correct |
514 ms |
60504 KB |
Output is correct |
52 |
Correct |
418 ms |
61112 KB |
Output is correct |
53 |
Correct |
542 ms |
76032 KB |
Output is correct |
54 |
Correct |
697 ms |
88672 KB |
Output is correct |
55 |
Correct |
548 ms |
75196 KB |
Output is correct |