답안 #69422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69422 2018-08-20T20:03:58 Z TadijaSebez Long Mansion (JOI17_long_mansion) C++11
100 / 100
586 ms 204068 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=500050;
int pos[N],lo[N],hi[N],c[N],l[N],r[N];
vector<int> a[N];
bool on(int l, int r, int x){ return l<=x && r>=x;}
bool can(int l, int r, int x){ return (lo[x] && on(l,r,lo[x])) || (hi[x] && on(l,r,hi[x]));}
int main()
{
	int n,q,i,j,x,y;
	scanf("%i",&n);
	for(i=1;i<n;i++) scanf("%i",&c[i]);
	for(i=1;i<=n;i++)
	{
		scanf("%i",&x);
		a[i].resize(x);
		for(j=0;j<x;j++) scanf("%i",&a[i][j]);
	}
	for(i=1;i<=n;i++) pos[i]=0;
	for(i=n;i>1;i--)
	{
		for(j=0;j<a[i].size();j++) pos[a[i][j]]=i;
		hi[i-1]=pos[c[i-1]];
	}
	for(i=1;i<=n;i++) pos[i]=0;
	for(i=1;i<n;i++)
	{
		for(j=0;j<a[i].size();j++) pos[a[i][j]]=i;
		lo[i]=pos[c[i]];
	}
	//for(i=1;i<n;i++) printf("->%i:%i %i\n",i,lo[i],hi[i]);
	for(i=1;i<=n;i++)
	{
		l[i]=r[i]=i;
		while(1)
		{
			if(l[i]>1 && can(l[i],r[i],l[i]-1))
			{
				//printf("%i %i\n",l[l[i]-1],r[l[i]-1]);
				r[i]=max(r[i],r[l[i]-1]);
				l[i]=l[l[i]-1];
			}
			else if(r[i]<n && can(l[i],r[i],r[i])) r[i]++;
			else break;
		}
		//printf("%i:%i %i\n",i,l[i],r[i]);
	}
	scanf("%i",&q);
	while(q--)
	{
		scanf("%i %i",&x,&y);
		if(on(l[x],r[x],y)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:25:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<a[i].size();j++) pos[a[i][j]]=i;
           ~^~~~~~~~~~~~
long_mansion.cpp:31:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<a[i].size();j++) pos[a[i][j]]=i;
           ~^~~~~~~~~~~~
long_mansion.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
long_mansion.cpp:15:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1;i<n;i++) scanf("%i",&c[i]);
                   ~~~~~^~~~~~~~~~~~
long_mansion.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i",&x);
   ~~~~~^~~~~~~~~
long_mansion.cpp:20:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(j=0;j<x;j++) scanf("%i",&a[i][j]);
                    ~~~~~^~~~~~~~~~~~~~~
long_mansion.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&q);
  ~~~~~^~~~~~~~~
long_mansion.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12280 KB Output is correct
2 Correct 15 ms 12392 KB Output is correct
3 Correct 15 ms 12460 KB Output is correct
4 Correct 14 ms 12460 KB Output is correct
5 Correct 14 ms 12460 KB Output is correct
6 Correct 15 ms 12476 KB Output is correct
7 Correct 14 ms 12476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12280 KB Output is correct
2 Correct 15 ms 12392 KB Output is correct
3 Correct 15 ms 12460 KB Output is correct
4 Correct 14 ms 12460 KB Output is correct
5 Correct 14 ms 12460 KB Output is correct
6 Correct 15 ms 12476 KB Output is correct
7 Correct 14 ms 12476 KB Output is correct
8 Correct 160 ms 13832 KB Output is correct
9 Correct 157 ms 13868 KB Output is correct
10 Correct 158 ms 14064 KB Output is correct
11 Correct 154 ms 14432 KB Output is correct
12 Correct 151 ms 14432 KB Output is correct
13 Correct 161 ms 14432 KB Output is correct
14 Correct 189 ms 14432 KB Output is correct
15 Correct 195 ms 14432 KB Output is correct
16 Correct 145 ms 14456 KB Output is correct
17 Correct 169 ms 14456 KB Output is correct
18 Correct 166 ms 14456 KB Output is correct
19 Correct 152 ms 14456 KB Output is correct
20 Correct 154 ms 14464 KB Output is correct
21 Correct 159 ms 14632 KB Output is correct
22 Correct 163 ms 14632 KB Output is correct
23 Correct 152 ms 14632 KB Output is correct
24 Correct 160 ms 14632 KB Output is correct
25 Correct 153 ms 14632 KB Output is correct
26 Correct 169 ms 14632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 277 ms 19588 KB Output is correct
2 Correct 280 ms 19872 KB Output is correct
3 Correct 271 ms 19872 KB Output is correct
4 Correct 275 ms 19872 KB Output is correct
5 Correct 279 ms 19872 KB Output is correct
6 Correct 270 ms 19872 KB Output is correct
7 Correct 222 ms 19876 KB Output is correct
8 Correct 250 ms 19876 KB Output is correct
9 Correct 250 ms 19884 KB Output is correct
10 Correct 264 ms 19884 KB Output is correct
11 Correct 308 ms 19884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12280 KB Output is correct
2 Correct 15 ms 12392 KB Output is correct
3 Correct 15 ms 12460 KB Output is correct
4 Correct 14 ms 12460 KB Output is correct
5 Correct 14 ms 12460 KB Output is correct
6 Correct 15 ms 12476 KB Output is correct
7 Correct 14 ms 12476 KB Output is correct
8 Correct 160 ms 13832 KB Output is correct
9 Correct 157 ms 13868 KB Output is correct
10 Correct 158 ms 14064 KB Output is correct
11 Correct 154 ms 14432 KB Output is correct
12 Correct 151 ms 14432 KB Output is correct
13 Correct 161 ms 14432 KB Output is correct
14 Correct 189 ms 14432 KB Output is correct
15 Correct 195 ms 14432 KB Output is correct
16 Correct 145 ms 14456 KB Output is correct
17 Correct 169 ms 14456 KB Output is correct
18 Correct 166 ms 14456 KB Output is correct
19 Correct 152 ms 14456 KB Output is correct
20 Correct 154 ms 14464 KB Output is correct
21 Correct 159 ms 14632 KB Output is correct
22 Correct 163 ms 14632 KB Output is correct
23 Correct 152 ms 14632 KB Output is correct
24 Correct 160 ms 14632 KB Output is correct
25 Correct 153 ms 14632 KB Output is correct
26 Correct 169 ms 14632 KB Output is correct
27 Correct 277 ms 19588 KB Output is correct
28 Correct 280 ms 19872 KB Output is correct
29 Correct 271 ms 19872 KB Output is correct
30 Correct 275 ms 19872 KB Output is correct
31 Correct 279 ms 19872 KB Output is correct
32 Correct 270 ms 19872 KB Output is correct
33 Correct 222 ms 19876 KB Output is correct
34 Correct 250 ms 19876 KB Output is correct
35 Correct 250 ms 19884 KB Output is correct
36 Correct 264 ms 19884 KB Output is correct
37 Correct 308 ms 19884 KB Output is correct
38 Correct 555 ms 43268 KB Output is correct
39 Correct 586 ms 60112 KB Output is correct
40 Correct 543 ms 60112 KB Output is correct
41 Correct 540 ms 80564 KB Output is correct
42 Correct 298 ms 80564 KB Output is correct
43 Correct 312 ms 80564 KB Output is correct
44 Correct 380 ms 89108 KB Output is correct
45 Correct 433 ms 99572 KB Output is correct
46 Correct 392 ms 109724 KB Output is correct
47 Correct 314 ms 111788 KB Output is correct
48 Correct 337 ms 119020 KB Output is correct
49 Correct 387 ms 134424 KB Output is correct
50 Correct 372 ms 144764 KB Output is correct
51 Correct 402 ms 155096 KB Output is correct
52 Correct 401 ms 164120 KB Output is correct
53 Correct 484 ms 180460 KB Output is correct
54 Correct 554 ms 198760 KB Output is correct
55 Correct 570 ms 204068 KB Output is correct