Submission #953644

# Submission time Handle Problem Language Result Execution time Memory
953644 2024-03-26T11:42:44 Z arashMLG Long Mansion (JOI17_long_mansion) C++17
100 / 100
530 ms 63404 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...)    69
#define debugArr(...)  69
#endif
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse4")

typedef long long     ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;

const int N = 5e5 + 23;
const ll inf = 1e18;

#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)

struct Seg {
	int t[N<<2];
	
	Seg() {
		fill(t,t+(N<<2),N);
	}
	
	void upd(int pos,int x,int v=1,int tl=0,int tr= N) {
		if(tr-tl == 1) {
			t[v] = min(t[v],x);
			return;
		}
		int mid=(tl+tr)/2;
		if(pos<mid)
			upd(pos,x,lc,tl,mid);
		else
			upd(pos,x,rc,mid,tr);
		t[v] = min(t[lc],t[rc]);
	}
	
	int get(int l,int r,int v=1,int tl=0,int tr= N) {
		if(l > r) return N;
		if(l == tl && r == tr-1) return t[v];
		int mid=(tl+tr)/2;
		return min( get(l,min(mid-1,r),lc,tl,mid) , get(max(l,mid),r,rc,mid,tr) );
	}
} L,R;

int n,q;
vector<int> vals[N];

bool check(int l,int r,int c) {
	if(vals[c].empty()) return false;
	if(vals[c].back() < l) return false;
	int x = *lower_bound(all(vals[c]),l);
	return x <= r;
}

int c[N];
int l[N],r[N];
int psl[N],psr[N];

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	for(int i = 1; i < n ; i ++) cin>>c[i];
	for(int i = 1; i <= n ; i++) {
		int x; cin>>x;
		while(x--) {
			int y; cin>>y;
			vals[y].pb(i);
		}
	}
	// calc l
	for(int i = 1; i <= n ; i++) {
		l[i] = i;
		while(l[i] > 1) {
			if(check(l[i],i,c[l[i]-1])) {
				l[i] --;
				l[i] = min(l[i],l[l[i]]);
			} else {
				break;
			}
		}
		L.upd(i,l[i]);
	}
	// calc r
	for(int i = n ; i >= 1; i--) {
		r[i] = i;
		while(r[i] < n) {
			if(check(i,r[i],c[r[i]])) {
				r[i] ++;
				r[i] = max(r[i],r[r[i]]);
			} else {
				break;
			}
		}
		R.upd(i,-r[i]);	
	}
	vector<int> ord(n);
	iota(all(ord),1);
	//shuffle(all(ord),rng);
	for(int i : ord) {
		while(true) {
			l[i] = L.get(l[i],r[i]);
			r[i] = -R.get(l[i],r[i]);
			bool x = false,y= false;
			if(l[i] > 1) {
				x = check(l[i],r[i],c[l[i]-1]);
			}
			if(r[i] < n) {
				y = check(l[i],r[i],c[r[i]]);
			}
			if(x) {
				l[i] --;	
			}
			if(y) {
				r[i] ++;
			}
			L.upd(i,l[i]);
			R.upd(i,-r[i]);
			if(x == false && y == false) break;
		}
		debug(i,l[i],r[i]);
	}
	/*for(int i = 2; i <= n ; i++) {
		psl[i] += psl[i-1];
		psr[i] += psr[i-1];
		if(l[i] <= i-1 || check(i,r[i],c[i-1])) {
			psl[i] ++;
			debug(i,"1");
		}
		if(r[i-1] >= i || check(l[i-1],i-1,c[i-1])) {
			psr[i] ++;
			debug(i,"2");
		}
	}*/
	cin>>q;
	while(q--) {
		int x,y; cin>>x>>y;
		cout<< (y <= r[x] && y >= l[x] ? "YES" : "NO") << '\n';
	}
	return 0;
}

// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!

Compilation message

long_mansion.cpp: In function 'int32_t main()':
long_mansion.cpp:5:23: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...)    69
      |                       ^~
long_mansion.cpp:132:3: note: in expansion of macro 'debug'
  132 |   debug(i,l[i],r[i]);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35420 KB Output is correct
2 Correct 10 ms 35416 KB Output is correct
3 Correct 12 ms 35416 KB Output is correct
4 Correct 9 ms 35420 KB Output is correct
5 Correct 8 ms 35416 KB Output is correct
6 Correct 8 ms 35420 KB Output is correct
7 Correct 9 ms 35528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35420 KB Output is correct
2 Correct 10 ms 35416 KB Output is correct
3 Correct 12 ms 35416 KB Output is correct
4 Correct 9 ms 35420 KB Output is correct
5 Correct 8 ms 35416 KB Output is correct
6 Correct 8 ms 35420 KB Output is correct
7 Correct 9 ms 35528 KB Output is correct
8 Correct 81 ms 41296 KB Output is correct
9 Correct 84 ms 41264 KB Output is correct
10 Correct 82 ms 41556 KB Output is correct
11 Correct 84 ms 41860 KB Output is correct
12 Correct 73 ms 41040 KB Output is correct
13 Correct 79 ms 41556 KB Output is correct
14 Correct 80 ms 41552 KB Output is correct
15 Correct 78 ms 41556 KB Output is correct
16 Correct 77 ms 41296 KB Output is correct
17 Correct 78 ms 41556 KB Output is correct
18 Correct 78 ms 41556 KB Output is correct
19 Correct 77 ms 41808 KB Output is correct
20 Correct 78 ms 41340 KB Output is correct
21 Correct 78 ms 41300 KB Output is correct
22 Correct 84 ms 41324 KB Output is correct
23 Correct 84 ms 41264 KB Output is correct
24 Correct 83 ms 41300 KB Output is correct
25 Correct 88 ms 41296 KB Output is correct
26 Correct 79 ms 41296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 46928 KB Output is correct
2 Correct 204 ms 46420 KB Output is correct
3 Correct 190 ms 46404 KB Output is correct
4 Correct 209 ms 46924 KB Output is correct
5 Correct 216 ms 46856 KB Output is correct
6 Correct 176 ms 45140 KB Output is correct
7 Correct 166 ms 45072 KB Output is correct
8 Correct 167 ms 44880 KB Output is correct
9 Correct 163 ms 45020 KB Output is correct
10 Correct 161 ms 44880 KB Output is correct
11 Correct 163 ms 44908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 35420 KB Output is correct
2 Correct 10 ms 35416 KB Output is correct
3 Correct 12 ms 35416 KB Output is correct
4 Correct 9 ms 35420 KB Output is correct
5 Correct 8 ms 35416 KB Output is correct
6 Correct 8 ms 35420 KB Output is correct
7 Correct 9 ms 35528 KB Output is correct
8 Correct 81 ms 41296 KB Output is correct
9 Correct 84 ms 41264 KB Output is correct
10 Correct 82 ms 41556 KB Output is correct
11 Correct 84 ms 41860 KB Output is correct
12 Correct 73 ms 41040 KB Output is correct
13 Correct 79 ms 41556 KB Output is correct
14 Correct 80 ms 41552 KB Output is correct
15 Correct 78 ms 41556 KB Output is correct
16 Correct 77 ms 41296 KB Output is correct
17 Correct 78 ms 41556 KB Output is correct
18 Correct 78 ms 41556 KB Output is correct
19 Correct 77 ms 41808 KB Output is correct
20 Correct 78 ms 41340 KB Output is correct
21 Correct 78 ms 41300 KB Output is correct
22 Correct 84 ms 41324 KB Output is correct
23 Correct 84 ms 41264 KB Output is correct
24 Correct 83 ms 41300 KB Output is correct
25 Correct 88 ms 41296 KB Output is correct
26 Correct 79 ms 41296 KB Output is correct
27 Correct 212 ms 46928 KB Output is correct
28 Correct 204 ms 46420 KB Output is correct
29 Correct 190 ms 46404 KB Output is correct
30 Correct 209 ms 46924 KB Output is correct
31 Correct 216 ms 46856 KB Output is correct
32 Correct 176 ms 45140 KB Output is correct
33 Correct 166 ms 45072 KB Output is correct
34 Correct 167 ms 44880 KB Output is correct
35 Correct 163 ms 45020 KB Output is correct
36 Correct 161 ms 44880 KB Output is correct
37 Correct 163 ms 44908 KB Output is correct
38 Correct 412 ms 53232 KB Output is correct
39 Correct 486 ms 53348 KB Output is correct
40 Correct 348 ms 51704 KB Output is correct
41 Correct 522 ms 50876 KB Output is correct
42 Correct 166 ms 46416 KB Output is correct
43 Correct 166 ms 46316 KB Output is correct
44 Correct 261 ms 51400 KB Output is correct
45 Correct 259 ms 51660 KB Output is correct
46 Correct 276 ms 52212 KB Output is correct
47 Correct 176 ms 46676 KB Output is correct
48 Correct 175 ms 46416 KB Output is correct
49 Correct 267 ms 51028 KB Output is correct
50 Correct 268 ms 51332 KB Output is correct
51 Correct 296 ms 52820 KB Output is correct
52 Correct 308 ms 52764 KB Output is correct
53 Correct 409 ms 57792 KB Output is correct
54 Correct 530 ms 63404 KB Output is correct
55 Correct 419 ms 58224 KB Output is correct