#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],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] = pos2[i] = N+1;
for (i = N-1; i >= 0; i--) {
S.insert(i);
if (i < N-1) pos2[C[i]] = i;
for (j = 0; j < A[i].size(); j++) {
pos[A[i][j]] = i;
if (pos2[A[i][j]] < N+1) S.erase(pos2[A[i][j]]),pos2[A[i][j]] = N+1;
}
int b = (i == 0) ? N:pos[C[i-1]]-1;
auto it = S.upper_bound(b);
while (it != S.begin()) {
it--;
b = *it;
if (i <= b) update(0,N-1,i,b,0,i,b);
else break;
}
}
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:116:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for (j = 0; j < A[i].size(); j++) {
| ~~^~~~~~~~~~~~~
long_mansion.cpp:103:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
long_mansion.cpp:104:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | for (i = 0; i < N-1; i++) scanf("%d",&C[i]),C[i]--;
| ~~~~~^~~~~~~~~~~~
long_mansion.cpp:106:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | scanf("%d",&B);
| ~~~~~^~~~~~~~~
long_mansion.cpp:108:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | for (j = 0; j < B; j++) scanf("%d",&A[i][j]),A[i][j]--;
| ~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:132:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
132 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
long_mansion.cpp:134:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | scanf("%d %d",&X,&Y);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
12236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
12236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
306 ms |
28932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
12236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |