#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int C[500000];
vi A[500000];
int pos[500000];
vi pos2[500000];
set<int> S;
int l[1 << 20],r[1 << 20];
int build(int s,int e,int i) {
if (s == e) {
l[i] = 0,r[i] = 1e9;
return 0;
}
int mid = (s+e) / 2;
build(s,mid,2*i+1),build(mid+1,e,2*i+2);
l[i] = 0,r[i] = 1e9;
return 0;
}
int update(int s,int e,int as,int ae,int i,int ll,int rr) {
if ((s > ae) || (e < as)) return 0;
else if ((s >= as) && (e <= ae)) {
l[i] = max(l[i],ll),r[i] = min(r[i],rr);
return 0;
}
int mid = (s+e) / 2;
update(s,mid,as,ae,2*i+1,ll,rr),update(mid+1,e,as,ae,2*i+2,ll,rr);
return 0;
}
int L[500000],R[500000];
int queryAll(int s,int e,int i) {
if (s == e) {
L[s] = l[i],R[s] = r[i];
return 0;
}
int mid = (s+e) / 2;
l[2*i+1] = max(l[2*i+1],l[i]);
l[2*i+2] = max(l[2*i+2],l[i]);
r[2*i+1] = min(r[2*i+1],r[i]);
r[2*i+2] = min(r[2*i+2],r[i]);
queryAll(s,mid,2*i+1),queryAll(mid+1,e,2*i+2);
return 0;
}
int main() {
int i,j;
int N,Q,B;
scanf("%d",&N);
for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--;
for (i = 0; i < N; i++) {
scanf("%d",&B);
A[i].resize(B);
for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--;
}
build(0,N-1,0);
for (i = 0; i < N; i++) pos[i] = N+1;
for (i = N-1; i >= 0; i--) {
S.insert(i);
if (i < N-1) pos2[C[i]].pb(i);
for (j = 0; j < A[i].size(); j++) {
pos[A[i][j]] = i;
while (!pos2[A[i][j]].empty()) {
S.erase(pos2[A[i][j]].back());
pos2[A[i][j]].pop_back();
}
}
int b = (i == 0) ? N:pos[C[i-1]]-1;
auto it = S.upper_bound(b);
if (it != S.begin()) {
it--;
b = *it;
if (i <= b) update(0,N-1,i,b,0,i,b);
}
}
for (i = 0; i < N; i++) pos[i] = -1,pos2[i].clear();
S.clear();
for (i = 0; i < N; i++) {
S.insert(i);
if (i > 0) pos2[C[i-1]].pb(i);
for (j = 0; j < A[i].size(); j++) {
pos[A[i][j]] = i;
while (!pos2[A[i][j]].empty()) {
S.erase(pos2[A[i][j]].back());
pos2[A[i][j]].pop_back();
}
}
int b = (i == N-1) ? 0:pos[C[i]]+1;
auto it = S.lower_bound(b);
if (it != S.end()) {
b = *it;
if (b <= i) update(0,N-1,b,i,0,b,i);
}
}
queryAll(0,N-1,0);
int X,Y;
scanf("%d",&Q);
for (i = 0; i < Q; i++) {
scanf("%d %d",&X,&Y);
X--,Y--;
if ((Y >= L[X]) && (Y <= R[X])) printf("YES\n");
else printf("NO\n");
}
return 0;
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:117:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for (j = 0; j < A[i].size(); j++) {
| ~~^~~~~~~~~~~~~
long_mansion.cpp:137:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
137 | for (j = 0; j < A[i].size(); j++) {
| ~~^~~~~~~~~~~~~
long_mansion.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
long_mansion.cpp:105:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--;
| ~~~~~^~~~~~~~~~~~
long_mansion.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | scanf("%d",&B);
| ~~~~~^~~~~~~~~
long_mansion.cpp:109:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--;
| ~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:154:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
154 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
long_mansion.cpp:156:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
156 | scanf("%d %d",&X,&Y);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23884 KB |
Output is correct |
2 |
Correct |
18 ms |
23964 KB |
Output is correct |
3 |
Correct |
19 ms |
24208 KB |
Output is correct |
4 |
Correct |
17 ms |
23884 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24016 KB |
Output is correct |
7 |
Correct |
18 ms |
24020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23884 KB |
Output is correct |
2 |
Correct |
18 ms |
23964 KB |
Output is correct |
3 |
Correct |
19 ms |
24208 KB |
Output is correct |
4 |
Correct |
17 ms |
23884 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24016 KB |
Output is correct |
7 |
Correct |
18 ms |
24020 KB |
Output is correct |
8 |
Correct |
148 ms |
25564 KB |
Output is correct |
9 |
Correct |
146 ms |
25540 KB |
Output is correct |
10 |
Correct |
148 ms |
25800 KB |
Output is correct |
11 |
Correct |
150 ms |
26004 KB |
Output is correct |
12 |
Correct |
144 ms |
25668 KB |
Output is correct |
13 |
Correct |
148 ms |
25748 KB |
Output is correct |
14 |
Correct |
144 ms |
26636 KB |
Output is correct |
15 |
Correct |
144 ms |
26612 KB |
Output is correct |
16 |
Correct |
144 ms |
26768 KB |
Output is correct |
17 |
Correct |
148 ms |
26564 KB |
Output is correct |
18 |
Correct |
161 ms |
26504 KB |
Output is correct |
19 |
Correct |
150 ms |
26600 KB |
Output is correct |
20 |
Correct |
142 ms |
26692 KB |
Output is correct |
21 |
Correct |
153 ms |
26836 KB |
Output is correct |
22 |
Correct |
145 ms |
26612 KB |
Output is correct |
23 |
Correct |
146 ms |
26440 KB |
Output is correct |
24 |
Correct |
150 ms |
26460 KB |
Output is correct |
25 |
Correct |
151 ms |
26436 KB |
Output is correct |
26 |
Correct |
147 ms |
26568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
32396 KB |
Output is correct |
2 |
Correct |
296 ms |
32384 KB |
Output is correct |
3 |
Correct |
281 ms |
32704 KB |
Output is correct |
4 |
Correct |
302 ms |
32312 KB |
Output is correct |
5 |
Correct |
302 ms |
32324 KB |
Output is correct |
6 |
Correct |
228 ms |
32384 KB |
Output is correct |
7 |
Correct |
216 ms |
33244 KB |
Output is correct |
8 |
Correct |
212 ms |
33152 KB |
Output is correct |
9 |
Correct |
214 ms |
32980 KB |
Output is correct |
10 |
Correct |
214 ms |
33032 KB |
Output is correct |
11 |
Correct |
214 ms |
33088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23884 KB |
Output is correct |
2 |
Correct |
18 ms |
23964 KB |
Output is correct |
3 |
Correct |
19 ms |
24208 KB |
Output is correct |
4 |
Correct |
17 ms |
23884 KB |
Output is correct |
5 |
Correct |
17 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
24016 KB |
Output is correct |
7 |
Correct |
18 ms |
24020 KB |
Output is correct |
8 |
Correct |
148 ms |
25564 KB |
Output is correct |
9 |
Correct |
146 ms |
25540 KB |
Output is correct |
10 |
Correct |
148 ms |
25800 KB |
Output is correct |
11 |
Correct |
150 ms |
26004 KB |
Output is correct |
12 |
Correct |
144 ms |
25668 KB |
Output is correct |
13 |
Correct |
148 ms |
25748 KB |
Output is correct |
14 |
Correct |
144 ms |
26636 KB |
Output is correct |
15 |
Correct |
144 ms |
26612 KB |
Output is correct |
16 |
Correct |
144 ms |
26768 KB |
Output is correct |
17 |
Correct |
148 ms |
26564 KB |
Output is correct |
18 |
Correct |
161 ms |
26504 KB |
Output is correct |
19 |
Correct |
150 ms |
26600 KB |
Output is correct |
20 |
Correct |
142 ms |
26692 KB |
Output is correct |
21 |
Correct |
153 ms |
26836 KB |
Output is correct |
22 |
Correct |
145 ms |
26612 KB |
Output is correct |
23 |
Correct |
146 ms |
26440 KB |
Output is correct |
24 |
Correct |
150 ms |
26460 KB |
Output is correct |
25 |
Correct |
151 ms |
26436 KB |
Output is correct |
26 |
Correct |
147 ms |
26568 KB |
Output is correct |
27 |
Correct |
307 ms |
32396 KB |
Output is correct |
28 |
Correct |
296 ms |
32384 KB |
Output is correct |
29 |
Correct |
281 ms |
32704 KB |
Output is correct |
30 |
Correct |
302 ms |
32312 KB |
Output is correct |
31 |
Correct |
302 ms |
32324 KB |
Output is correct |
32 |
Correct |
228 ms |
32384 KB |
Output is correct |
33 |
Correct |
216 ms |
33244 KB |
Output is correct |
34 |
Correct |
212 ms |
33152 KB |
Output is correct |
35 |
Correct |
214 ms |
32980 KB |
Output is correct |
36 |
Correct |
214 ms |
33032 KB |
Output is correct |
37 |
Correct |
214 ms |
33088 KB |
Output is correct |
38 |
Correct |
1240 ms |
60296 KB |
Output is correct |
39 |
Correct |
1209 ms |
68444 KB |
Output is correct |
40 |
Correct |
861 ms |
58308 KB |
Output is correct |
41 |
Correct |
563 ms |
66896 KB |
Output is correct |
42 |
Correct |
290 ms |
41508 KB |
Output is correct |
43 |
Correct |
267 ms |
40524 KB |
Output is correct |
44 |
Correct |
394 ms |
51868 KB |
Output is correct |
45 |
Correct |
394 ms |
52404 KB |
Output is correct |
46 |
Correct |
382 ms |
52980 KB |
Output is correct |
47 |
Correct |
235 ms |
41248 KB |
Output is correct |
48 |
Correct |
236 ms |
39816 KB |
Output is correct |
49 |
Correct |
332 ms |
50380 KB |
Output is correct |
50 |
Correct |
350 ms |
51524 KB |
Output is correct |
51 |
Correct |
368 ms |
53480 KB |
Output is correct |
52 |
Correct |
545 ms |
57928 KB |
Output is correct |
53 |
Correct |
756 ms |
72700 KB |
Output is correct |
54 |
Correct |
1004 ms |
85700 KB |
Output is correct |
55 |
Correct |
787 ms |
74236 KB |
Output is correct |