답안 #412605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412605 2021-05-27T07:20:31 Z 장태환(#7565) Bread First Search (CCO21_day2problem2) C++17
25 / 25
469 ms 5844 KB
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int stree[1<<19];
int lazy[1 << 19];
int mi[200100];
int dp[200100];
int treeN;
void ul(int i)
{
	stree[i] += lazy[i];
	if (i < treeN)
	{
		lazy[i * 2] += lazy[i];
		lazy[i * 2 + 1] += lazy[i];
	}
	lazy[i] = 0;
}
void update(int s, int e, int qs, int qe, int v, int i)
{
	ul(i);
	if (s > qe || qs > e||qs>qe)
		return;
	if (qs <= s && e <= qe)
	{
		lazy[i] += v;
		ul(i);
		return;
	}
	update(s, (s + e) / 2, qs, qe, v, i * 2);
	update((s + e) / 2+1,e, qs, qe, v, i * 2+1);
	stree[i] = min(stree[i * 2], stree[i * 2 + 1]);
}
int ge(int s, int e, int qs, int qe, int i)
{
	ul(i);
	if (s > qe || qs > e||qs>qe)
		return 1<<30;
	if (qs <= s && e <= qe)
	{
		return stree[i];
	}
	return min(ge(s, (s + e) / 2, qs, qe, i * 2),ge((s + e) / 2 + 1, e, qs, qe, i * 2 + 1));
}
int rmi[200100];
int main()
{
	int N, M;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> M;
	if (N == 1)
	{
		cout << 0;
		return 0;
	}
	int i;
	for (i = 1; i <= N; i++)
	{
		mi[i] = i;
	}
	for (treeN = 1; treeN < N; treeN *= 2);
	for (i = 1; i <= M; i++)
	{
		int a, b;
		cin >> a >> b;
		mi[a] = min(mi[a], b);
		mi[b] = min(mi[b], a);
	}
	for (i = 1; i <= N; i++)
		rmi[i] = mi[i];
	for (i = N-1; i > 0; i--)
	{
		mi[i] = min(mi[i], mi[i + 1]);
	}
	memset(dp, 1, sizeof(dp));
	dp[1] = 0;
	update(0, treeN - 1, 1, rmi[2] - 1, 1, 1);
	mi[N + 1] = N;
	for (i = 3; i <= N+1; i++)
	{
		int curan = ge(0, treeN - 1, 1, min(i - 2, mi[i] - 1), 1);
		if (i > N)
		{
			cout << curan;
			break;
		}
		update(0, treeN - 1, i - 1, i - 1, curan, 1);
		update(0, treeN - 1, 1, rmi[i] - 1, 1, 1);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 2 ms 1100 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 2 ms 1100 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 2 ms 1100 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 9 ms 1228 KB Output is correct
24 Correct 8 ms 1264 KB Output is correct
25 Correct 11 ms 1356 KB Output is correct
26 Correct 11 ms 1236 KB Output is correct
27 Correct 12 ms 1228 KB Output is correct
28 Correct 14 ms 1228 KB Output is correct
29 Correct 7 ms 1232 KB Output is correct
30 Correct 14 ms 1228 KB Output is correct
31 Correct 14 ms 1176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 2 ms 1100 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1100 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 2 ms 1100 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 2 ms 1100 KB Output is correct
23 Correct 9 ms 1228 KB Output is correct
24 Correct 8 ms 1264 KB Output is correct
25 Correct 11 ms 1356 KB Output is correct
26 Correct 11 ms 1236 KB Output is correct
27 Correct 12 ms 1228 KB Output is correct
28 Correct 14 ms 1228 KB Output is correct
29 Correct 7 ms 1232 KB Output is correct
30 Correct 14 ms 1228 KB Output is correct
31 Correct 14 ms 1176 KB Output is correct
32 Correct 413 ms 5748 KB Output is correct
33 Correct 409 ms 5804 KB Output is correct
34 Correct 346 ms 4676 KB Output is correct
35 Correct 469 ms 5796 KB Output is correct
36 Correct 461 ms 5736 KB Output is correct
37 Correct 452 ms 5800 KB Output is correct
38 Correct 385 ms 5800 KB Output is correct
39 Correct 387 ms 5844 KB Output is correct
40 Correct 204 ms 3556 KB Output is correct
41 Correct 361 ms 4648 KB Output is correct
42 Correct 434 ms 5804 KB Output is correct
43 Correct 447 ms 5760 KB Output is correct
44 Correct 1 ms 1100 KB Output is correct
45 Correct 1 ms 1100 KB Output is correct