답안 #511253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
511253 2022-01-15T13:04:32 Z ArianKheirandish Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 33048 KB
// in the name of God//
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x)    cerr << #x << " = " << x << endl;
const int maxn = 5e5 + 10;
int n, q;
vector<int> a[maxn], keys[maxn];
int b[maxn], c[maxn];
int dpL[maxn], dpR[maxn];

bool check(int l, int r, int x){
	int ind = lower_bound(keys[x].begin(),keys[x].end(), l) - keys[x].begin();
	if(ind < keys[x].size() && keys[x][ind] <= r)
		return 1;
	else
		return 0;
}

int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n;
	for(int i = 1 ; i < n ; i ++)
		cin >> c[i];
		
	for(int i = 1 ; i <= n ; i ++){
		cin >> b[i];
		for(int j = 0 ; j < b[i] ; j ++){
			int x;
			cin >> x;
			a[i].push_back(x);
		}
		for(auto x : a[i])
			keys[x].push_back(i);
	}
	
	for(int i = 1 ; i <= n ; i ++)
		dpL[i] = dpR[i] = i;
		
	for(int i = 1 ; i <= n ; i ++){
		while(1){
			if(dpL[i] > 1 && check(dpL[i], dpR[i], c[dpL[i] - 1]))
				dpR[i] = max(dpR[i], dpR[dpL[dpL[i] - 1]]),
				dpL[i] = dpL[dpL[i] - 1];
		
			else if(dpR[i] < n && check(dpL[i], dpR[i], c[dpR[i]]))
				dpR[i] = dpR[i] + 1;
			
			else
				break;
		}
		
		//debug(i);
	}
	
	cin >> q;
	while(q --){
		int x, y;
		cin >> x >> y;
		cout << ((dpL[x] <= y && y <= dpR[x]) ? "YES" : "NO") << '\n';
	}
	return 0;
}

Compilation message

long_mansion.cpp: In function 'bool check(int, int, int)':
long_mansion.cpp:15:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  if(ind < keys[x].size() && keys[x][ind] <= r)
      |     ~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23932 KB Output is correct
2 Correct 48 ms 24088 KB Output is correct
3 Correct 117 ms 24156 KB Output is correct
4 Correct 17 ms 23944 KB Output is correct
5 Correct 15 ms 24016 KB Output is correct
6 Correct 23 ms 23924 KB Output is correct
7 Correct 19 ms 23956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23932 KB Output is correct
2 Correct 48 ms 24088 KB Output is correct
3 Correct 117 ms 24156 KB Output is correct
4 Correct 17 ms 23944 KB Output is correct
5 Correct 15 ms 24016 KB Output is correct
6 Correct 23 ms 23924 KB Output is correct
7 Correct 19 ms 23956 KB Output is correct
8 Correct 140 ms 29868 KB Output is correct
9 Correct 175 ms 29780 KB Output is correct
10 Correct 179 ms 30188 KB Output is correct
11 Correct 245 ms 30464 KB Output is correct
12 Correct 150 ms 29412 KB Output is correct
13 Correct 147 ms 29948 KB Output is correct
14 Correct 155 ms 30024 KB Output is correct
15 Correct 129 ms 29968 KB Output is correct
16 Correct 114 ms 29836 KB Output is correct
17 Correct 110 ms 30052 KB Output is correct
18 Correct 113 ms 30024 KB Output is correct
19 Correct 113 ms 30024 KB Output is correct
20 Correct 157 ms 30028 KB Output is correct
21 Correct 116 ms 29788 KB Output is correct
22 Correct 126 ms 29856 KB Output is correct
23 Correct 129 ms 29772 KB Output is correct
24 Correct 113 ms 29832 KB Output is correct
25 Correct 130 ms 29804 KB Output is correct
26 Correct 144 ms 29816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3098 ms 33048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23932 KB Output is correct
2 Correct 48 ms 24088 KB Output is correct
3 Correct 117 ms 24156 KB Output is correct
4 Correct 17 ms 23944 KB Output is correct
5 Correct 15 ms 24016 KB Output is correct
6 Correct 23 ms 23924 KB Output is correct
7 Correct 19 ms 23956 KB Output is correct
8 Correct 140 ms 29868 KB Output is correct
9 Correct 175 ms 29780 KB Output is correct
10 Correct 179 ms 30188 KB Output is correct
11 Correct 245 ms 30464 KB Output is correct
12 Correct 150 ms 29412 KB Output is correct
13 Correct 147 ms 29948 KB Output is correct
14 Correct 155 ms 30024 KB Output is correct
15 Correct 129 ms 29968 KB Output is correct
16 Correct 114 ms 29836 KB Output is correct
17 Correct 110 ms 30052 KB Output is correct
18 Correct 113 ms 30024 KB Output is correct
19 Correct 113 ms 30024 KB Output is correct
20 Correct 157 ms 30028 KB Output is correct
21 Correct 116 ms 29788 KB Output is correct
22 Correct 126 ms 29856 KB Output is correct
23 Correct 129 ms 29772 KB Output is correct
24 Correct 113 ms 29832 KB Output is correct
25 Correct 130 ms 29804 KB Output is correct
26 Correct 144 ms 29816 KB Output is correct
27 Execution timed out 3098 ms 33048 KB Time limit exceeded
28 Halted 0 ms 0 KB -