Submission #953650

# Submission time Handle Problem Language Result Execution time Memory
953650 2024-03-26T11:48:00 Z arashMLG Long Mansion (JOI17_long_mansion) C++17
25 / 100
3000 ms 26448 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)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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;
			}
		}
		//debug(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;
			}
		}
		//debug(i,r[i]);	
	}
	vector<int> ord(n);
	iota(all(ord),1);
	//shuffle(all(ord),rng);
	for(int i : ord) {
		while(true) {
			l[i] = min(l[i],l[l[i]]);
			r[i] = max(r[i],r[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] --;
				continue;	
			}
			if(y) {
				r[i] ++;
				continue;
			}
			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:106:3: note: in expansion of macro 'debug'
  106 |   debug(i,l[i],r[i]);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19800 KB Output is correct
2 Correct 6 ms 19804 KB Output is correct
3 Correct 7 ms 19648 KB Output is correct
4 Correct 6 ms 19804 KB Output is correct
5 Correct 6 ms 19800 KB Output is correct
6 Correct 5 ms 19804 KB Output is correct
7 Correct 10 ms 19804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19800 KB Output is correct
2 Correct 6 ms 19804 KB Output is correct
3 Correct 7 ms 19648 KB Output is correct
4 Correct 6 ms 19804 KB Output is correct
5 Correct 6 ms 19800 KB Output is correct
6 Correct 5 ms 19804 KB Output is correct
7 Correct 10 ms 19804 KB Output is correct
8 Correct 80 ms 21328 KB Output is correct
9 Correct 79 ms 21284 KB Output is correct
10 Correct 80 ms 21324 KB Output is correct
11 Correct 79 ms 21460 KB Output is correct
12 Correct 71 ms 21332 KB Output is correct
13 Correct 76 ms 21320 KB Output is correct
14 Correct 75 ms 21332 KB Output is correct
15 Correct 75 ms 21596 KB Output is correct
16 Correct 87 ms 21776 KB Output is correct
17 Correct 76 ms 21388 KB Output is correct
18 Correct 74 ms 21376 KB Output is correct
19 Correct 76 ms 21332 KB Output is correct
20 Correct 77 ms 21688 KB Output is correct
21 Correct 76 ms 21616 KB Output is correct
22 Correct 74 ms 21328 KB Output is correct
23 Correct 91 ms 21568 KB Output is correct
24 Correct 79 ms 21332 KB Output is correct
25 Correct 82 ms 21332 KB Output is correct
26 Correct 79 ms 21180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 24148 KB Output is correct
2 Correct 149 ms 23536 KB Output is correct
3 Correct 143 ms 23664 KB Output is correct
4 Correct 156 ms 23892 KB Output is correct
5 Correct 153 ms 24104 KB Output is correct
6 Correct 134 ms 23120 KB Output is correct
7 Correct 121 ms 23304 KB Output is correct
8 Correct 127 ms 23280 KB Output is correct
9 Correct 112 ms 23120 KB Output is correct
10 Correct 107 ms 23376 KB Output is correct
11 Correct 109 ms 23128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19800 KB Output is correct
2 Correct 6 ms 19804 KB Output is correct
3 Correct 7 ms 19648 KB Output is correct
4 Correct 6 ms 19804 KB Output is correct
5 Correct 6 ms 19800 KB Output is correct
6 Correct 5 ms 19804 KB Output is correct
7 Correct 10 ms 19804 KB Output is correct
8 Correct 80 ms 21328 KB Output is correct
9 Correct 79 ms 21284 KB Output is correct
10 Correct 80 ms 21324 KB Output is correct
11 Correct 79 ms 21460 KB Output is correct
12 Correct 71 ms 21332 KB Output is correct
13 Correct 76 ms 21320 KB Output is correct
14 Correct 75 ms 21332 KB Output is correct
15 Correct 75 ms 21596 KB Output is correct
16 Correct 87 ms 21776 KB Output is correct
17 Correct 76 ms 21388 KB Output is correct
18 Correct 74 ms 21376 KB Output is correct
19 Correct 76 ms 21332 KB Output is correct
20 Correct 77 ms 21688 KB Output is correct
21 Correct 76 ms 21616 KB Output is correct
22 Correct 74 ms 21328 KB Output is correct
23 Correct 91 ms 21568 KB Output is correct
24 Correct 79 ms 21332 KB Output is correct
25 Correct 82 ms 21332 KB Output is correct
26 Correct 79 ms 21180 KB Output is correct
27 Correct 158 ms 24148 KB Output is correct
28 Correct 149 ms 23536 KB Output is correct
29 Correct 143 ms 23664 KB Output is correct
30 Correct 156 ms 23892 KB Output is correct
31 Correct 153 ms 24104 KB Output is correct
32 Correct 134 ms 23120 KB Output is correct
33 Correct 121 ms 23304 KB Output is correct
34 Correct 127 ms 23280 KB Output is correct
35 Correct 112 ms 23120 KB Output is correct
36 Correct 107 ms 23376 KB Output is correct
37 Correct 109 ms 23128 KB Output is correct
38 Correct 209 ms 25832 KB Output is correct
39 Correct 241 ms 26152 KB Output is correct
40 Correct 195 ms 25424 KB Output is correct
41 Correct 287 ms 25396 KB Output is correct
42 Correct 118 ms 23424 KB Output is correct
43 Correct 121 ms 23124 KB Output is correct
44 Correct 178 ms 25676 KB Output is correct
45 Correct 205 ms 25700 KB Output is correct
46 Correct 173 ms 25940 KB Output is correct
47 Correct 121 ms 23576 KB Output is correct
48 Correct 119 ms 23196 KB Output is correct
49 Correct 180 ms 25084 KB Output is correct
50 Correct 160 ms 25680 KB Output is correct
51 Correct 170 ms 26448 KB Output is correct
52 Execution timed out 3024 ms 26448 KB Time limit exceeded
53 Halted 0 ms 0 KB -