답안 #69912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69912 2018-08-22T00:28:17 Z MatheusLealV Long Mansion (JOI17_long_mansion) C++17
10 / 100
3000 ms 99544 KB
#include <bits/stdc++.h>
#define N 500050
using namespace std;

int n, q, c[N], L[N], R[N];

vector<int> pos[N];

void solve(int l, int r, int i)
{
	L[i] = min(L[i], l);

	R[i] = max(R[i], r);

	bool ok = false;

	if(r < n)
	{
		int q = upper_bound(pos[c[r]].begin(), pos[c[r]].end(), r) - lower_bound(pos[c[r]].begin(), pos[c[r]].end(), l);
		
		if(q) solve(l, r + 1, i), ok = 1;
	}

	if(l > 1 and !ok)
	{
		int q = upper_bound(pos[c[l - 1]].begin(), pos[c[l - 1]].end(), r) - lower_bound(pos[c[l - 1]].begin(), pos[c[l - 1]].end(), l);
		
		if(q) solve(l - 1, r, i);		
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n;

	for(int i = 1; i < n; i++) cin>>c[i];

	for(int i = 1; i <= n; i++)
	{
		L[i] = R[i] = i;

		int a, b;

		cin>>a;

		for(int x = 1; x <= a; x++)
		{
			cin>>b;

			pos[b].push_back(i);
		}
	}

	for(int i = 1; i <= n; i++) solve(i, i, i);

	cin>>q;

	for(int i = 1; i <= q; i++)
	{
		int x, y;

		cin>>x>>y;

		if(L[x] <= y and y <= R[x]) cout<<"YES\n";

		else cout<<"NO\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12280 KB Output is correct
2 Correct 230 ms 12460 KB Output is correct
3 Correct 1108 ms 12708 KB Output is correct
4 Correct 18 ms 12744 KB Output is correct
5 Correct 241 ms 12880 KB Output is correct
6 Correct 27 ms 12880 KB Output is correct
7 Correct 24 ms 12940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12280 KB Output is correct
2 Correct 230 ms 12460 KB Output is correct
3 Correct 1108 ms 12708 KB Output is correct
4 Correct 18 ms 12744 KB Output is correct
5 Correct 241 ms 12880 KB Output is correct
6 Correct 27 ms 12880 KB Output is correct
7 Correct 24 ms 12940 KB Output is correct
8 Correct 149 ms 18804 KB Output is correct
9 Correct 157 ms 23128 KB Output is correct
10 Correct 347 ms 27892 KB Output is correct
11 Correct 1196 ms 32692 KB Output is correct
12 Correct 173 ms 36436 KB Output is correct
13 Correct 161 ms 40764 KB Output is correct
14 Correct 174 ms 45124 KB Output is correct
15 Correct 210 ms 49620 KB Output is correct
16 Correct 384 ms 53580 KB Output is correct
17 Correct 146 ms 57740 KB Output is correct
18 Correct 143 ms 62244 KB Output is correct
19 Correct 160 ms 66520 KB Output is correct
20 Correct 317 ms 71048 KB Output is correct
21 Correct 372 ms 74876 KB Output is correct
22 Correct 194 ms 78744 KB Output is correct
23 Correct 138 ms 82952 KB Output is correct
24 Correct 138 ms 87124 KB Output is correct
25 Correct 205 ms 91392 KB Output is correct
26 Correct 146 ms 95764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3064 ms 99544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12280 KB Output is correct
2 Correct 230 ms 12460 KB Output is correct
3 Correct 1108 ms 12708 KB Output is correct
4 Correct 18 ms 12744 KB Output is correct
5 Correct 241 ms 12880 KB Output is correct
6 Correct 27 ms 12880 KB Output is correct
7 Correct 24 ms 12940 KB Output is correct
8 Correct 149 ms 18804 KB Output is correct
9 Correct 157 ms 23128 KB Output is correct
10 Correct 347 ms 27892 KB Output is correct
11 Correct 1196 ms 32692 KB Output is correct
12 Correct 173 ms 36436 KB Output is correct
13 Correct 161 ms 40764 KB Output is correct
14 Correct 174 ms 45124 KB Output is correct
15 Correct 210 ms 49620 KB Output is correct
16 Correct 384 ms 53580 KB Output is correct
17 Correct 146 ms 57740 KB Output is correct
18 Correct 143 ms 62244 KB Output is correct
19 Correct 160 ms 66520 KB Output is correct
20 Correct 317 ms 71048 KB Output is correct
21 Correct 372 ms 74876 KB Output is correct
22 Correct 194 ms 78744 KB Output is correct
23 Correct 138 ms 82952 KB Output is correct
24 Correct 138 ms 87124 KB Output is correct
25 Correct 205 ms 91392 KB Output is correct
26 Correct 146 ms 95764 KB Output is correct
27 Execution timed out 3064 ms 99544 KB Time limit exceeded
28 Halted 0 ms 0 KB -