Submission #723996

# Submission time Handle Problem Language Result Execution time Memory
723996 2023-04-14T15:15:07 Z NothingXD Long Mansion (JOI17_long_mansion) C++17
100 / 100
430 ms 46476 KB
/*

   Wei Wai Wei Wai
   Zumigat nan damu dimi kwayt rayt

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;
/*typedef __uint128_t L;
  struct FastMod {
  ull b, m;
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull reduce(ull a) {
  ull q = (ull)((L(m) * a) >> 64);
  ull r = a - q * b; // can be proven that 0 <= r < 2*b
  return r >= b ? r - b : r;
  }
  };
  FastMod FM(2);
  */
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 5e5 + 10;

int n, q, L[maxn], R[maxn], a[maxn];
vector<int> val[maxn];
bool mark[maxn];

void solve(int l, int r){
	if (l + 1 == r){
		L[l] = R[l] = l;
		return;
	}
	int mid = (l + r) >> 1;
	solve(l, mid);
	solve(mid, r);
	int ptl = mid, ptr = mid-1;
	for (int i = mid; i < r; i++){
		if (L[i] != mid) continue;
		while(ptr < R[i]){
			ptr++;
			for (auto x: val[ptr]) mark[x] = true;
		}
		while((ptl > l && mark[a[ptl-1]]) || (ptr + 1 < r && mark[a[ptr]])){
			if (ptl > l && mark[a[ptl-1]]){
				ptl--;
				for (auto x: val[ptl]) mark[x] = true;
			}
			if (ptr + 1 < r && mark[a[ptr]]){
				ptr++;
				for (auto x: val[ptr]) mark[x] = true;
			}
		}
		L[i] = ptl, R[i] = ptr;
	}
	for (int i = l; i < r; i++) for (auto x: val[i]) mark[x] = false;
	ptl = mid, ptr = mid-1;
	for (int i = mid-1; i >= l; i--){
		if (R[i] != mid-1) continue;
		while(ptl > L[i]){
			ptl--;
			for (auto x: val[ptl]) mark[x] = true;
		}
		while((ptl > l && mark[a[ptl-1]]) || (ptr + 1 < r && mark[a[ptr]])){
			if (ptl > l && mark[a[ptl-1]]){
				ptl--;
				for (auto x: val[ptl]) mark[x] = true;
			}
			if (ptr + 1 < r && mark[a[ptr]]){
				ptr++;
				for (auto x: val[ptr]) mark[x] = true;
			}
		}
		L[i] = ptl, R[i] = ptr;
	}
	for (int i = l; i < r; i++) for (auto x: val[i]) mark[x] = false;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n;
	for (int i = 1; i < n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++){
		int k; cin >> k;
		for (int j = 0; j < k; j++){
			int x; cin >> x;
			val[i].push_back(x);
		}
	}

	solve(1, n+1);
	cin >> q;
	while(q--){
		int u, v; cin >> u >> v;
		cout << (L[u] <= v && v <= R[u]? "YES\n": "NO\n");
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12264 KB Output is correct
2 Correct 10 ms 12220 KB Output is correct
3 Correct 10 ms 12372 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 8 ms 12164 KB Output is correct
6 Correct 10 ms 12212 KB Output is correct
7 Correct 8 ms 12224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12264 KB Output is correct
2 Correct 10 ms 12220 KB Output is correct
3 Correct 10 ms 12372 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 8 ms 12164 KB Output is correct
6 Correct 10 ms 12212 KB Output is correct
7 Correct 8 ms 12224 KB Output is correct
8 Correct 99 ms 18100 KB Output is correct
9 Correct 95 ms 17996 KB Output is correct
10 Correct 96 ms 18384 KB Output is correct
11 Correct 96 ms 18776 KB Output is correct
12 Correct 100 ms 17752 KB Output is correct
13 Correct 93 ms 18208 KB Output is correct
14 Correct 95 ms 18212 KB Output is correct
15 Correct 92 ms 18232 KB Output is correct
16 Correct 86 ms 18040 KB Output is correct
17 Correct 94 ms 18264 KB Output is correct
18 Correct 95 ms 18284 KB Output is correct
19 Correct 93 ms 18264 KB Output is correct
20 Correct 89 ms 18212 KB Output is correct
21 Correct 102 ms 17984 KB Output is correct
22 Correct 103 ms 18076 KB Output is correct
23 Correct 89 ms 17960 KB Output is correct
24 Correct 93 ms 17952 KB Output is correct
25 Correct 94 ms 18008 KB Output is correct
26 Correct 92 ms 18052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 25944 KB Output is correct
2 Correct 247 ms 25756 KB Output is correct
3 Correct 262 ms 25576 KB Output is correct
4 Correct 253 ms 25844 KB Output is correct
5 Correct 268 ms 25828 KB Output is correct
6 Correct 191 ms 24548 KB Output is correct
7 Correct 205 ms 24332 KB Output is correct
8 Correct 187 ms 24404 KB Output is correct
9 Correct 180 ms 24396 KB Output is correct
10 Correct 183 ms 24460 KB Output is correct
11 Correct 189 ms 24344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12264 KB Output is correct
2 Correct 10 ms 12220 KB Output is correct
3 Correct 10 ms 12372 KB Output is correct
4 Correct 9 ms 12224 KB Output is correct
5 Correct 8 ms 12164 KB Output is correct
6 Correct 10 ms 12212 KB Output is correct
7 Correct 8 ms 12224 KB Output is correct
8 Correct 99 ms 18100 KB Output is correct
9 Correct 95 ms 17996 KB Output is correct
10 Correct 96 ms 18384 KB Output is correct
11 Correct 96 ms 18776 KB Output is correct
12 Correct 100 ms 17752 KB Output is correct
13 Correct 93 ms 18208 KB Output is correct
14 Correct 95 ms 18212 KB Output is correct
15 Correct 92 ms 18232 KB Output is correct
16 Correct 86 ms 18040 KB Output is correct
17 Correct 94 ms 18264 KB Output is correct
18 Correct 95 ms 18284 KB Output is correct
19 Correct 93 ms 18264 KB Output is correct
20 Correct 89 ms 18212 KB Output is correct
21 Correct 102 ms 17984 KB Output is correct
22 Correct 103 ms 18076 KB Output is correct
23 Correct 89 ms 17960 KB Output is correct
24 Correct 93 ms 17952 KB Output is correct
25 Correct 94 ms 18008 KB Output is correct
26 Correct 92 ms 18052 KB Output is correct
27 Correct 259 ms 25944 KB Output is correct
28 Correct 247 ms 25756 KB Output is correct
29 Correct 262 ms 25576 KB Output is correct
30 Correct 253 ms 25844 KB Output is correct
31 Correct 268 ms 25828 KB Output is correct
32 Correct 191 ms 24548 KB Output is correct
33 Correct 205 ms 24332 KB Output is correct
34 Correct 187 ms 24404 KB Output is correct
35 Correct 180 ms 24396 KB Output is correct
36 Correct 183 ms 24460 KB Output is correct
37 Correct 189 ms 24344 KB Output is correct
38 Correct 335 ms 42412 KB Output is correct
39 Correct 331 ms 46476 KB Output is correct
40 Correct 307 ms 36948 KB Output is correct
41 Correct 430 ms 44972 KB Output is correct
42 Correct 203 ms 25536 KB Output is correct
43 Correct 165 ms 25628 KB Output is correct
44 Correct 298 ms 32608 KB Output is correct
45 Correct 250 ms 32724 KB Output is correct
46 Correct 278 ms 32948 KB Output is correct
47 Correct 182 ms 25656 KB Output is correct
48 Correct 195 ms 25412 KB Output is correct
49 Correct 276 ms 32552 KB Output is correct
50 Correct 303 ms 32616 KB Output is correct
51 Correct 311 ms 33140 KB Output is correct
52 Correct 231 ms 31628 KB Output is correct
53 Correct 316 ms 37692 KB Output is correct
54 Correct 336 ms 43692 KB Output is correct
55 Correct 302 ms 37860 KB Output is correct