답안 #26403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26403 2017-06-30T01:02:29 Z pacu Long Mansion (JOI17_long_mansion) C++
100 / 100
1106 ms 140540 KB
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define MAXN 500005

int N,Q;
int len[MAXN];
vector<int> keys[MAXN];
int req[MAXN];	//req[i] is for i to i+1
int nearLeft[MAXN];
int nearRight[MAXN];
vector<int> lstLeft[MAXN];
vector<int> lstRight[MAXN];
int vRight[MAXN];
int vLeft[MAXN];

int occ[MAXN];

set<int> sLeft,sRight;
int l[MAXN],r[MAXN];

int main()
{
	scanf("%d",&N);
	for(int i=1;i<N;i++)
	{
		scanf("%d",&req[i]);
		req[i]--;
	}
	req[0] = req[N] = N;
	int a,b;
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&len[i]);
		for(int j=0;j<len[i];j++)
		{
			scanf("%d",&a);
			a--;
			keys[i].push_back(a);
		}
	}
	for(int i=0;i<=N;i++)
		occ[i] = 0;
	nearLeft[0] = 0;
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<len[i];j++)
			occ[keys[i][j]] = i;
		nearLeft[i] = occ[req[i]];
		lstLeft[nearLeft[i]].push_back(i);
	}
	for(int i=0;i<=N;i++)
		occ[i] = N+1;
	nearRight[N] = N+1;
	for(int i=N;i>0;i--)
	{
		for(int j=0;j<len[i];j++)
			occ[keys[i][j]] = i;
		nearRight[i-1] = occ[req[i-1]];
		lstRight[nearRight[i-1]].push_back(i-1);
	}
	set<int>::iterator it;
	for(int i=0;i<=N;i++)
	{
		for(int j=0;j<lstLeft[i].size();j++)
			sRight.insert(lstLeft[i][j]);
		it = sRight.lower_bound(nearRight[i]);
		it--;
		vRight[i] = *it;
	}
	for(int i=N+1;i>0;i--)
	{
		for(int j=0;j<lstRight[i].size();j++)
			sLeft.insert(lstRight[i][j]);
		it = sLeft.lower_bound(nearLeft[i-1]);
		vLeft[i-1] = *it;
	}
	vector<int> v;
	for(int i=1;i<=N;i++)
	{
		v.push_back(i);
		while(v.size()>0 && v.back() > vLeft[i])
		{
			r[v.back()] = i;
			v.pop_back();
		}
	}
	v.clear();
	for(int i=N-1;i>=0;i--)
	{
		v.push_back(i+1);
		while(v.size()>0 && v.back() <= vRight[i])
		{
			l[v.back()] = i+1;
			v.pop_back();
		}
	}
	int Q;
	scanf("%d",&Q);
	int x,y;
	for(int i=0;i<Q;i++)
	{
		scanf("%d %d",&x,&y);
		if(l[x] <= y && y <= r[x]) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<lstLeft[i].size();j++)
                ^
long_mansion.cpp:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<lstRight[i].size();j++)
                ^
long_mansion.cpp:33:8: warning: unused variable 'b' [-Wunused-variable]
  int a,b;
        ^
long_mansion.cpp:26:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
long_mansion.cpp:29:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&req[i]);
                      ^
long_mansion.cpp:36:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&len[i]);
                      ^
long_mansion.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&a);
                  ^
long_mansion.cpp:101:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&Q);
                ^
long_mansion.cpp:105:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 54312 KB Output is correct
2 Correct 16 ms 54444 KB Output is correct
3 Correct 9 ms 54840 KB Output is correct
4 Correct 13 ms 54312 KB Output is correct
5 Correct 16 ms 54312 KB Output is correct
6 Correct 13 ms 54312 KB Output is correct
7 Correct 6 ms 54312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 54312 KB Output is correct
2 Correct 16 ms 54444 KB Output is correct
3 Correct 9 ms 54840 KB Output is correct
4 Correct 13 ms 54312 KB Output is correct
5 Correct 16 ms 54312 KB Output is correct
6 Correct 13 ms 54312 KB Output is correct
7 Correct 6 ms 54312 KB Output is correct
8 Correct 136 ms 54312 KB Output is correct
9 Correct 163 ms 54312 KB Output is correct
10 Correct 213 ms 54444 KB Output is correct
11 Correct 183 ms 54844 KB Output is correct
12 Correct 129 ms 54048 KB Output is correct
13 Correct 133 ms 54312 KB Output is correct
14 Correct 136 ms 54312 KB Output is correct
15 Correct 149 ms 54312 KB Output is correct
16 Correct 136 ms 54312 KB Output is correct
17 Correct 139 ms 54312 KB Output is correct
18 Correct 203 ms 54312 KB Output is correct
19 Correct 176 ms 54312 KB Output is correct
20 Correct 126 ms 54312 KB Output is correct
21 Correct 186 ms 54312 KB Output is correct
22 Correct 149 ms 54312 KB Output is correct
23 Correct 179 ms 54312 KB Output is correct
24 Correct 163 ms 54312 KB Output is correct
25 Correct 193 ms 54312 KB Output is correct
26 Correct 163 ms 54312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 71088 KB Output is correct
2 Correct 383 ms 71236 KB Output is correct
3 Correct 353 ms 71460 KB Output is correct
4 Correct 359 ms 71076 KB Output is correct
5 Correct 373 ms 71088 KB Output is correct
6 Correct 299 ms 72184 KB Output is correct
7 Correct 279 ms 73172 KB Output is correct
8 Correct 293 ms 73308 KB Output is correct
9 Correct 259 ms 73356 KB Output is correct
10 Correct 329 ms 73464 KB Output is correct
11 Correct 256 ms 73460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 54312 KB Output is correct
2 Correct 16 ms 54444 KB Output is correct
3 Correct 9 ms 54840 KB Output is correct
4 Correct 13 ms 54312 KB Output is correct
5 Correct 16 ms 54312 KB Output is correct
6 Correct 13 ms 54312 KB Output is correct
7 Correct 6 ms 54312 KB Output is correct
8 Correct 136 ms 54312 KB Output is correct
9 Correct 163 ms 54312 KB Output is correct
10 Correct 213 ms 54444 KB Output is correct
11 Correct 183 ms 54844 KB Output is correct
12 Correct 129 ms 54048 KB Output is correct
13 Correct 133 ms 54312 KB Output is correct
14 Correct 136 ms 54312 KB Output is correct
15 Correct 149 ms 54312 KB Output is correct
16 Correct 136 ms 54312 KB Output is correct
17 Correct 139 ms 54312 KB Output is correct
18 Correct 203 ms 54312 KB Output is correct
19 Correct 176 ms 54312 KB Output is correct
20 Correct 126 ms 54312 KB Output is correct
21 Correct 186 ms 54312 KB Output is correct
22 Correct 149 ms 54312 KB Output is correct
23 Correct 179 ms 54312 KB Output is correct
24 Correct 163 ms 54312 KB Output is correct
25 Correct 193 ms 54312 KB Output is correct
26 Correct 163 ms 54312 KB Output is correct
27 Correct 366 ms 71088 KB Output is correct
28 Correct 383 ms 71236 KB Output is correct
29 Correct 353 ms 71460 KB Output is correct
30 Correct 359 ms 71076 KB Output is correct
31 Correct 373 ms 71088 KB Output is correct
32 Correct 299 ms 72184 KB Output is correct
33 Correct 279 ms 73172 KB Output is correct
34 Correct 293 ms 73308 KB Output is correct
35 Correct 259 ms 73356 KB Output is correct
36 Correct 329 ms 73464 KB Output is correct
37 Correct 256 ms 73460 KB Output is correct
38 Correct 1106 ms 116880 KB Output is correct
39 Correct 973 ms 132588 KB Output is correct
40 Correct 749 ms 101304 KB Output is correct
41 Correct 813 ms 140540 KB Output is correct
42 Correct 349 ms 71660 KB Output is correct
43 Correct 313 ms 72264 KB Output is correct
44 Correct 523 ms 91008 KB Output is correct
45 Correct 513 ms 91140 KB Output is correct
46 Correct 476 ms 91272 KB Output is correct
47 Correct 289 ms 73120 KB Output is correct
48 Correct 293 ms 73092 KB Output is correct
49 Correct 489 ms 91572 KB Output is correct
50 Correct 506 ms 91844 KB Output is correct
51 Correct 553 ms 92256 KB Output is correct
52 Correct 473 ms 87092 KB Output is correct
53 Correct 696 ms 103628 KB Output is correct
54 Correct 866 ms 119400 KB Output is correct
55 Correct 613 ms 103288 KB Output is correct