/* code by PixelCat */
/* meow owo */
#include <bits/stdc++.h>
#define int LL //__int128
#define double long double
using namespace std;
using LL = long long;
// using i128 = __int128_t;
using ull = unsigned long long;
using pii = pair<int, int>;
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(998244353)
// #define MOD (int)((LL)1'000'000'007)
#define INF (int)(4e18)
#define EPS (1e-6)
namespace PixelCat {
#ifdef NYAOWO
#include "/home/pixelcat/yodayo/meow/library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
inline void NYA() {
ios::sync_with_stdio(false);
cin.tie(0);
}
inline int gcd(int a, int b) {
return __gcd(a, b);
}
inline int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int fpow(int b, int p, const int &mod = MOD) {
int ans = 1;
for (; p; p >>= 1, b = b * b % mod)
if (p & 1) ans = ans * b % mod;
return ans;
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
if (_a < _b) _a = _b;
}
mt19937_64 rng(
chrono::steady_clock::now().time_since_epoch().count());
} // namespace PixelCat
using namespace PixelCat;
const int MAXN = 500050;
int key[MAXN];
vector<int> pos[MAXN];
pii ans[MAXN];
// check if there's any key of type [k] in range [l, r]
bool check(int l, int r, int k) {
return lower_bound(all(pos[k]), l) != upper_bound(all(pos[k]), r);
}
struct Ayaya {
vector<int> start;
int l, r, sl, sr;
Ayaya(int s): start(1, s), l(s), r(s), sl(s), sr(s) {}
int len() { return r - l + 1; }
bool inside(int x) { return l <= x && x <= r; }
void dead() { for(auto &i:start) ans[i] = pii(l, r); }
bool expand(int n) {
if(r < n && check(l, r, key[r])) {
r++; return true;
} else if(l > 1 && check(l, r, key[l - 1])) {
l--; return true;
}
return false;
}
};
Ayaya* merge(Ayaya *a, Ayaya *b) {
if(sz(a->start) < sz(b->start)) swap(a, b);
a->start.insert(a->start.end(), all(b->start));
a->l = min(a->l, b->l);
a->sl = min(a->sl, b->sl);
a->r = max(a->r, b->r);
a->sr = max(a->sr, b->sr);
return a;
}
bool overlap(Ayaya *a, Ayaya *b) {
return (a->inside(b->sl) || a->inside(b->sr)) &&
(b->inside(a->sl) || b->inside(a->sr));
}
void solve(int n) {
For(i, 1, n) {
Ayaya aya(i);
while(aya.expand(n));
aya.dead();
}
}
int32_t main() {
NYA();
// nyaacho >/////<
int n; cin >> n;
For(i, 1, n - 1) cin >> key[i];
For(i, 1, n) {
int k; cin >> k;
while(k--) {
int x; cin >> x;
pos[x].eb(i);
}
}
solve(n);
int q; cin >> q;
while(q--) {
int x, y; cin >> x >> y;
pii &r = ans[x];
if(r.F <= y && y <= r.S) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12244 KB |
Output is correct |
2 |
Correct |
150 ms |
12284 KB |
Output is correct |
3 |
Correct |
726 ms |
12324 KB |
Output is correct |
4 |
Correct |
9 ms |
12220 KB |
Output is correct |
5 |
Correct |
147 ms |
12232 KB |
Output is correct |
6 |
Correct |
17 ms |
12248 KB |
Output is correct |
7 |
Correct |
13 ms |
12228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12244 KB |
Output is correct |
2 |
Correct |
150 ms |
12284 KB |
Output is correct |
3 |
Correct |
726 ms |
12324 KB |
Output is correct |
4 |
Correct |
9 ms |
12220 KB |
Output is correct |
5 |
Correct |
147 ms |
12232 KB |
Output is correct |
6 |
Correct |
17 ms |
12248 KB |
Output is correct |
7 |
Correct |
13 ms |
12228 KB |
Output is correct |
8 |
Correct |
116 ms |
18000 KB |
Output is correct |
9 |
Correct |
86 ms |
17976 KB |
Output is correct |
10 |
Correct |
235 ms |
18372 KB |
Output is correct |
11 |
Correct |
784 ms |
18776 KB |
Output is correct |
12 |
Correct |
92 ms |
17600 KB |
Output is correct |
13 |
Correct |
76 ms |
18236 KB |
Output is correct |
14 |
Correct |
77 ms |
18288 KB |
Output is correct |
15 |
Correct |
129 ms |
18296 KB |
Output is correct |
16 |
Correct |
211 ms |
18036 KB |
Output is correct |
17 |
Correct |
77 ms |
18220 KB |
Output is correct |
18 |
Correct |
77 ms |
18252 KB |
Output is correct |
19 |
Correct |
79 ms |
18188 KB |
Output is correct |
20 |
Correct |
181 ms |
18172 KB |
Output is correct |
21 |
Correct |
218 ms |
17988 KB |
Output is correct |
22 |
Correct |
91 ms |
18124 KB |
Output is correct |
23 |
Correct |
84 ms |
17984 KB |
Output is correct |
24 |
Correct |
84 ms |
18052 KB |
Output is correct |
25 |
Correct |
85 ms |
18092 KB |
Output is correct |
26 |
Correct |
86 ms |
18056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3070 ms |
19336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12244 KB |
Output is correct |
2 |
Correct |
150 ms |
12284 KB |
Output is correct |
3 |
Correct |
726 ms |
12324 KB |
Output is correct |
4 |
Correct |
9 ms |
12220 KB |
Output is correct |
5 |
Correct |
147 ms |
12232 KB |
Output is correct |
6 |
Correct |
17 ms |
12248 KB |
Output is correct |
7 |
Correct |
13 ms |
12228 KB |
Output is correct |
8 |
Correct |
116 ms |
18000 KB |
Output is correct |
9 |
Correct |
86 ms |
17976 KB |
Output is correct |
10 |
Correct |
235 ms |
18372 KB |
Output is correct |
11 |
Correct |
784 ms |
18776 KB |
Output is correct |
12 |
Correct |
92 ms |
17600 KB |
Output is correct |
13 |
Correct |
76 ms |
18236 KB |
Output is correct |
14 |
Correct |
77 ms |
18288 KB |
Output is correct |
15 |
Correct |
129 ms |
18296 KB |
Output is correct |
16 |
Correct |
211 ms |
18036 KB |
Output is correct |
17 |
Correct |
77 ms |
18220 KB |
Output is correct |
18 |
Correct |
77 ms |
18252 KB |
Output is correct |
19 |
Correct |
79 ms |
18188 KB |
Output is correct |
20 |
Correct |
181 ms |
18172 KB |
Output is correct |
21 |
Correct |
218 ms |
17988 KB |
Output is correct |
22 |
Correct |
91 ms |
18124 KB |
Output is correct |
23 |
Correct |
84 ms |
17984 KB |
Output is correct |
24 |
Correct |
84 ms |
18052 KB |
Output is correct |
25 |
Correct |
85 ms |
18092 KB |
Output is correct |
26 |
Correct |
86 ms |
18056 KB |
Output is correct |
27 |
Execution timed out |
3070 ms |
19336 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |