답안 #125284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125284 2019-07-05T04:35:44 Z 구재현(#3066) Long Mansion (JOI17_long_mansion) C++14
10 / 100
3000 ms 20728 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
using lint = long long;
using pi = pair<int, int>;

int n, c[MAXN];
vector<int> key_loc[MAXN];

int L[MAXN], R[MAXN];
int up[MAXN], dn[MAXN];
pi rng[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++) scanf("%d",&c[i]);
	for(int i=1; i<=n; i++){
		int x; scanf("%d",&x);
		for(int j=0; j<x; j++){
			int y; scanf("%d",&y);
			key_loc[y].push_back(i);
		}
	}
	for(int i=1; i<n; i++){
		auto p = lower_bound(key_loc[c[i]].begin(), key_loc[c[i]].end(), i + 1);
		if(p == key_loc[c[i]].end()) R[i] = n + 1;
		else R[i] = *p;
		if(p == key_loc[c[i]].begin()) L[i] = 0;
		else L[i] = *prev(p);
	}
	R[0] = n + 1;
	L[n + 1] = 0;
	fill(rng + 1, rng + n + 1, pi(1, n));
	memset(dn, 0x3f, sizeof(dn));
	for(int i=1; i<=n; i++){
		for(int j=i; j<=n; j++){
			if(L[j] < i && R[i - 1] > j){
				dn[j] = min(dn[j], i);
				up[i] = max(up[i], j);
			}
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=i; j<=n; j++){
			if(dn[j] <= i){
				rng[i].second = j;
				break;
			}
		}
		for(int j=i; j>=1; j--){
			if(up[j] >= i){
				rng[i].first = j;
				break;
			}
		}
	}
	int q; scanf("%d",&q);
	while(q--){
		int x, y; scanf("%d %d",&x,&y);
		puts(rng[x].first <= y && y <= rng[x].second ? "YES" : "NO");
	}
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
long_mansion.cpp:16:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<n; i++) scanf("%d",&c[i]);
                         ~~~~~^~~~~~~~~~~~
long_mansion.cpp:18:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x; scanf("%d",&x);
          ~~~~~^~~~~~~~~
long_mansion.cpp:20:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int y; scanf("%d",&y);
           ~~~~~^~~~~~~~~
long_mansion.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int q; scanf("%d",&q);
         ~~~~~^~~~~~~~~
long_mansion.cpp:59:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d %d",&x,&y);
             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 14204 KB Output is correct
2 Correct 24 ms 14328 KB Output is correct
3 Correct 39 ms 14328 KB Output is correct
4 Correct 20 ms 14328 KB Output is correct
5 Correct 22 ms 14200 KB Output is correct
6 Correct 20 ms 14200 KB Output is correct
7 Correct 21 ms 14200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 14204 KB Output is correct
2 Correct 24 ms 14328 KB Output is correct
3 Correct 39 ms 14328 KB Output is correct
4 Correct 20 ms 14328 KB Output is correct
5 Correct 22 ms 14200 KB Output is correct
6 Correct 20 ms 14200 KB Output is correct
7 Correct 21 ms 14200 KB Output is correct
8 Correct 150 ms 20088 KB Output is correct
9 Correct 150 ms 20088 KB Output is correct
10 Correct 158 ms 20348 KB Output is correct
11 Correct 169 ms 20728 KB Output is correct
12 Correct 139 ms 19704 KB Output is correct
13 Correct 147 ms 20216 KB Output is correct
14 Correct 146 ms 20248 KB Output is correct
15 Correct 144 ms 20216 KB Output is correct
16 Correct 141 ms 20088 KB Output is correct
17 Correct 145 ms 20236 KB Output is correct
18 Correct 145 ms 20216 KB Output is correct
19 Correct 144 ms 20216 KB Output is correct
20 Correct 143 ms 20240 KB Output is correct
21 Correct 141 ms 20052 KB Output is correct
22 Correct 145 ms 20216 KB Output is correct
23 Correct 148 ms 20088 KB Output is correct
24 Correct 148 ms 19988 KB Output is correct
25 Correct 148 ms 20236 KB Output is correct
26 Correct 148 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3021 ms 20720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 14204 KB Output is correct
2 Correct 24 ms 14328 KB Output is correct
3 Correct 39 ms 14328 KB Output is correct
4 Correct 20 ms 14328 KB Output is correct
5 Correct 22 ms 14200 KB Output is correct
6 Correct 20 ms 14200 KB Output is correct
7 Correct 21 ms 14200 KB Output is correct
8 Correct 150 ms 20088 KB Output is correct
9 Correct 150 ms 20088 KB Output is correct
10 Correct 158 ms 20348 KB Output is correct
11 Correct 169 ms 20728 KB Output is correct
12 Correct 139 ms 19704 KB Output is correct
13 Correct 147 ms 20216 KB Output is correct
14 Correct 146 ms 20248 KB Output is correct
15 Correct 144 ms 20216 KB Output is correct
16 Correct 141 ms 20088 KB Output is correct
17 Correct 145 ms 20236 KB Output is correct
18 Correct 145 ms 20216 KB Output is correct
19 Correct 144 ms 20216 KB Output is correct
20 Correct 143 ms 20240 KB Output is correct
21 Correct 141 ms 20052 KB Output is correct
22 Correct 145 ms 20216 KB Output is correct
23 Correct 148 ms 20088 KB Output is correct
24 Correct 148 ms 19988 KB Output is correct
25 Correct 148 ms 20236 KB Output is correct
26 Correct 148 ms 19960 KB Output is correct
27 Execution timed out 3021 ms 20720 KB Time limit exceeded
28 Halted 0 ms 0 KB -