#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 500005
struct thing {
int x, y, i;
bool operator< (const thing& o) const {
return MP(x, y) < MP(o.x, o.y);
}
};
int n;
int c[MAXN];
int b[MAXN];
vi a[MAXN];
int q;
ii range[MAXN];
bool ans[MAXN], key[MAXN];
int main() {
scanf("%d", &n);
REP (i, 1, n) {
scanf("%d", &c[i]);
}
REP (i, 1, n + 1) {
scanf("%d", &b[i]);
a[i].resize(b[i] + 5);
REP (j, 1, b[i] + 1) {
scanf("%d", &a[i][j]);
}
}
REP (i, 1, n + 1) {
int l = i, r = i;
vi tmp;
REP (j, 1, b[l] + 1) {
key[a[l][j]] = 1;
tmp.pb(a[l][j]);
}
while (1) {
bool prog = 0;
while (l != 1 && key[c[l - 1]]) {
l--;
REP (j, 1, b[l] + 1) {
key[a[l][j]] = 1;
tmp.pb(a[l][j]);
}
prog = 1;
}
while (r != n && key[c[r]]) {
r++;
REP (j, 1, b[r] + 1) {
key[a[r][j]] = 1;
tmp.pb(a[r][j]);
}
prog = 1;
}
if (!prog) break;
}
for (int &j : tmp) {
key[j] = 0;
}
debug("%d: %d %d\n", i, l, r);
range[i] = MP(l, r);
}
scanf("%d", &q);
REP (i, 0, q) {
int x, y; scanf("%d%d", &x, &y);
ans[i] = y >= range[x].FI && y <= range[x].SE;
}
REP (i, 0, q) {
if (ans[i]) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
/*
5
1 2 3 4
2 2 3
1 1
1 1
1 3
1 4
4
2 4
4 2
1 5
5 3
*/
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d", &c[i]);
| ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d", &b[i]);
| ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:66:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d", &a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
long_mansion.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
long_mansion.cpp:104:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | int x, y; scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12236 KB |
Output is correct |
2 |
Correct |
62 ms |
12248 KB |
Output is correct |
3 |
Correct |
145 ms |
12440 KB |
Output is correct |
4 |
Correct |
14 ms |
12212 KB |
Output is correct |
5 |
Correct |
82 ms |
12196 KB |
Output is correct |
6 |
Correct |
24 ms |
12192 KB |
Output is correct |
7 |
Correct |
22 ms |
12200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12236 KB |
Output is correct |
2 |
Correct |
62 ms |
12248 KB |
Output is correct |
3 |
Correct |
145 ms |
12440 KB |
Output is correct |
4 |
Correct |
14 ms |
12212 KB |
Output is correct |
5 |
Correct |
82 ms |
12196 KB |
Output is correct |
6 |
Correct |
24 ms |
12192 KB |
Output is correct |
7 |
Correct |
22 ms |
12200 KB |
Output is correct |
8 |
Correct |
146 ms |
14232 KB |
Output is correct |
9 |
Correct |
143 ms |
14160 KB |
Output is correct |
10 |
Correct |
221 ms |
14432 KB |
Output is correct |
11 |
Correct |
282 ms |
14472 KB |
Output is correct |
12 |
Correct |
146 ms |
14276 KB |
Output is correct |
13 |
Correct |
146 ms |
14384 KB |
Output is correct |
14 |
Correct |
133 ms |
14360 KB |
Output is correct |
15 |
Correct |
180 ms |
14476 KB |
Output is correct |
16 |
Correct |
205 ms |
14588 KB |
Output is correct |
17 |
Correct |
141 ms |
14396 KB |
Output is correct |
18 |
Correct |
143 ms |
14384 KB |
Output is correct |
19 |
Correct |
162 ms |
14436 KB |
Output is correct |
20 |
Correct |
192 ms |
14532 KB |
Output is correct |
21 |
Correct |
206 ms |
14656 KB |
Output is correct |
22 |
Correct |
160 ms |
14532 KB |
Output is correct |
23 |
Correct |
175 ms |
14236 KB |
Output is correct |
24 |
Correct |
149 ms |
14232 KB |
Output is correct |
25 |
Correct |
171 ms |
14144 KB |
Output is correct |
26 |
Correct |
149 ms |
14192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3075 ms |
21792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12236 KB |
Output is correct |
2 |
Correct |
62 ms |
12248 KB |
Output is correct |
3 |
Correct |
145 ms |
12440 KB |
Output is correct |
4 |
Correct |
14 ms |
12212 KB |
Output is correct |
5 |
Correct |
82 ms |
12196 KB |
Output is correct |
6 |
Correct |
24 ms |
12192 KB |
Output is correct |
7 |
Correct |
22 ms |
12200 KB |
Output is correct |
8 |
Correct |
146 ms |
14232 KB |
Output is correct |
9 |
Correct |
143 ms |
14160 KB |
Output is correct |
10 |
Correct |
221 ms |
14432 KB |
Output is correct |
11 |
Correct |
282 ms |
14472 KB |
Output is correct |
12 |
Correct |
146 ms |
14276 KB |
Output is correct |
13 |
Correct |
146 ms |
14384 KB |
Output is correct |
14 |
Correct |
133 ms |
14360 KB |
Output is correct |
15 |
Correct |
180 ms |
14476 KB |
Output is correct |
16 |
Correct |
205 ms |
14588 KB |
Output is correct |
17 |
Correct |
141 ms |
14396 KB |
Output is correct |
18 |
Correct |
143 ms |
14384 KB |
Output is correct |
19 |
Correct |
162 ms |
14436 KB |
Output is correct |
20 |
Correct |
192 ms |
14532 KB |
Output is correct |
21 |
Correct |
206 ms |
14656 KB |
Output is correct |
22 |
Correct |
160 ms |
14532 KB |
Output is correct |
23 |
Correct |
175 ms |
14236 KB |
Output is correct |
24 |
Correct |
149 ms |
14232 KB |
Output is correct |
25 |
Correct |
171 ms |
14144 KB |
Output is correct |
26 |
Correct |
149 ms |
14192 KB |
Output is correct |
27 |
Execution timed out |
3075 ms |
21792 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |