Submission #432187

# Submission time Handle Problem Language Result Execution time Memory
432187 2021-06-18T01:35:34 Z jamezzz Long Mansion (JOI17_long_mansion) C++17
100 / 100
506 ms 41412 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define maxn 500005

int n,c[maxn],b,t,q,x,y,cl[maxn],cr[maxn],l[maxn],r[maxn];
vi v[maxn];

bool can(int x,int l,int r){
	//current range is [l,r], can u travel through door x
	int pos=lower_bound(all(v[c[x]]),l)-v[c[x]].begin();
	if(pos==sz(v[c[x]])||v[c[x]][pos]>r)return false;
	return true;
}

ii thing(int l,int r){
	if(l>1&&can(l-1,l,r))return thing(cl[l-1],r);
	if(r<n&&can(r,l,r))return thing(l,cr[r+1]);
	return ii(l,r);
}

int main(){
	sf("%d",&n);
	for(int i=1;i<n;++i)sf("%d",&c[i]);
	for(int i=1;i<=n;++i){
		sf("%d",&b);
		for(int j=0;j<b;++j){
			sf("%d",&t);
			v[t].pb(i);
		}
	}
	for(int i=1;i<=n;++i){
		cl[i]=i;
		while(1<cl[i]&&can(cl[i]-1,cl[i],i))cl[i]=cl[cl[i]-1];
	}
	for(int i=n;i>=1;--i){
		cr[i]=i;
		while(cr[i]<n&&can(cr[i],i,cr[i]))cr[i]=cr[cr[i]+1];
	}
	for(int i=1;i<=n;++i){
		if(i>1&&can(i-1,i,cr[i])){
			l[i]=l[i-1];
			r[i]=max(r[i-1],cr[i]);
		}
		else{
			l[i]=cl[i];r[i]=cr[i];
		}
		tie(l[i],r[i])=thing(l[i],r[i]);
	}
	sf("%d",&q);
	while(q--){
		sf("%d%d",&x,&y);
		if(l[x]<=y&&y<=r[x])pf("YES\n");
		else pf("NO\n");
	}
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:43:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  sf("%d",&n);
      |    ^
long_mansion.cpp:44:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  for(int i=1;i<n;++i)sf("%d",&c[i]);
      |                        ^
long_mansion.cpp:46:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   sf("%d",&b);
      |     ^
long_mansion.cpp:48:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |    sf("%d",&t);
      |      ^
long_mansion.cpp:70:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  sf("%d",&q);
      |    ^
long_mansion.cpp:72:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   sf("%d%d",&x,&y);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12236 KB Output is correct
2 Correct 12 ms 12248 KB Output is correct
3 Correct 13 ms 12284 KB Output is correct
4 Correct 12 ms 12236 KB Output is correct
5 Correct 11 ms 12108 KB Output is correct
6 Correct 11 ms 12236 KB Output is correct
7 Correct 11 ms 12196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12236 KB Output is correct
2 Correct 12 ms 12248 KB Output is correct
3 Correct 13 ms 12284 KB Output is correct
4 Correct 12 ms 12236 KB Output is correct
5 Correct 11 ms 12108 KB Output is correct
6 Correct 11 ms 12236 KB Output is correct
7 Correct 11 ms 12196 KB Output is correct
8 Correct 145 ms 17984 KB Output is correct
9 Correct 139 ms 17916 KB Output is correct
10 Correct 143 ms 18372 KB Output is correct
11 Correct 143 ms 18692 KB Output is correct
12 Correct 139 ms 17608 KB Output is correct
13 Correct 137 ms 18156 KB Output is correct
14 Correct 133 ms 18232 KB Output is correct
15 Correct 153 ms 18200 KB Output is correct
16 Correct 131 ms 18056 KB Output is correct
17 Correct 139 ms 18240 KB Output is correct
18 Correct 151 ms 18152 KB Output is correct
19 Correct 140 ms 18220 KB Output is correct
20 Correct 164 ms 18232 KB Output is correct
21 Correct 133 ms 17992 KB Output is correct
22 Correct 132 ms 18064 KB Output is correct
23 Correct 164 ms 17972 KB Output is correct
24 Correct 137 ms 17992 KB Output is correct
25 Correct 137 ms 17948 KB Output is correct
26 Correct 136 ms 17940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 25252 KB Output is correct
2 Correct 281 ms 24760 KB Output is correct
3 Correct 264 ms 24596 KB Output is correct
4 Correct 303 ms 25100 KB Output is correct
5 Correct 297 ms 25096 KB Output is correct
6 Correct 234 ms 23364 KB Output is correct
7 Correct 230 ms 23236 KB Output is correct
8 Correct 208 ms 23180 KB Output is correct
9 Correct 207 ms 23208 KB Output is correct
10 Correct 226 ms 23368 KB Output is correct
11 Correct 205 ms 23104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12236 KB Output is correct
2 Correct 12 ms 12248 KB Output is correct
3 Correct 13 ms 12284 KB Output is correct
4 Correct 12 ms 12236 KB Output is correct
5 Correct 11 ms 12108 KB Output is correct
6 Correct 11 ms 12236 KB Output is correct
7 Correct 11 ms 12196 KB Output is correct
8 Correct 145 ms 17984 KB Output is correct
9 Correct 139 ms 17916 KB Output is correct
10 Correct 143 ms 18372 KB Output is correct
11 Correct 143 ms 18692 KB Output is correct
12 Correct 139 ms 17608 KB Output is correct
13 Correct 137 ms 18156 KB Output is correct
14 Correct 133 ms 18232 KB Output is correct
15 Correct 153 ms 18200 KB Output is correct
16 Correct 131 ms 18056 KB Output is correct
17 Correct 139 ms 18240 KB Output is correct
18 Correct 151 ms 18152 KB Output is correct
19 Correct 140 ms 18220 KB Output is correct
20 Correct 164 ms 18232 KB Output is correct
21 Correct 133 ms 17992 KB Output is correct
22 Correct 132 ms 18064 KB Output is correct
23 Correct 164 ms 17972 KB Output is correct
24 Correct 137 ms 17992 KB Output is correct
25 Correct 137 ms 17948 KB Output is correct
26 Correct 136 ms 17940 KB Output is correct
27 Correct 303 ms 25252 KB Output is correct
28 Correct 281 ms 24760 KB Output is correct
29 Correct 264 ms 24596 KB Output is correct
30 Correct 303 ms 25100 KB Output is correct
31 Correct 297 ms 25096 KB Output is correct
32 Correct 234 ms 23364 KB Output is correct
33 Correct 230 ms 23236 KB Output is correct
34 Correct 208 ms 23180 KB Output is correct
35 Correct 207 ms 23208 KB Output is correct
36 Correct 226 ms 23368 KB Output is correct
37 Correct 205 ms 23104 KB Output is correct
38 Correct 426 ms 32536 KB Output is correct
39 Correct 479 ms 34500 KB Output is correct
40 Correct 406 ms 30856 KB Output is correct
41 Correct 506 ms 35272 KB Output is correct
42 Correct 260 ms 24880 KB Output is correct
43 Correct 223 ms 24660 KB Output is correct
44 Correct 435 ms 29680 KB Output is correct
45 Correct 382 ms 29632 KB Output is correct
46 Correct 356 ms 29784 KB Output is correct
47 Correct 235 ms 24900 KB Output is correct
48 Correct 209 ms 24356 KB Output is correct
49 Correct 319 ms 29100 KB Output is correct
50 Correct 370 ms 29256 KB Output is correct
51 Correct 455 ms 30148 KB Output is correct
52 Correct 264 ms 32568 KB Output is correct
53 Correct 357 ms 36144 KB Output is correct
54 Correct 504 ms 41412 KB Output is correct
55 Correct 331 ms 36292 KB Output is correct