답안 #145050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145050 2019-08-18T14:22:17 Z faremy Global Warming (CEOI18_glo) C++14
100 / 100
503 ms 9432 KB
#include <iostream>
#include <algorithm>
#include <set>


struct Seq
{
	Seq(int v, int s) : maxVal(v), size(s) {}
	int maxVal, size;
	
	bool operator <(const Seq &other) const
	{
		return (maxVal < other.maxVal);
	}
};

const int MAXN = 2e5;

int temp[MAXN];
int lis[MAXN], lds[MAXN];

std::set<Seq> stacket;


void insert(Seq sequence)
{
	while (stacket.lower_bound(sequence) != stacket.end() && stacket.lower_bound(sequence)->size <= sequence.size)
		stacket.erase(stacket.lower_bound(sequence));
	std::set<Seq>::iterator prev = stacket.upper_bound(sequence);

	prev--;
	if (prev->size < sequence.size)
		stacket.emplace(sequence);
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cout.tie(nullptr);
	std::cin.tie(nullptr);

	int days, maxOffset;
	std::cin >> days >> maxOffset;

	for (int iDay = 0; iDay < days; iDay++)
		std::cin >> temp[iDay];

	stacket.emplace(0, 0);
	for (int iDay = 0; iDay < days; iDay++)
	{
		std::set<Seq>::iterator prev = stacket.lower_bound(Seq(temp[iDay], 1));
		prev--;
		lis[iDay] = prev->size + 1;
		insert(Seq(temp[iDay], lis[iDay]));
	}

	stacket.clear();

	stacket.emplace(-2e9, 0);
	for (int iDay = days - 1; iDay > -1; iDay--)
	{
		std::set<Seq>::iterator prev = stacket.lower_bound(Seq(-temp[iDay], 1));
		prev--;
		lds[iDay] = prev->size + 1;
		insert(Seq(-temp[iDay], lds[iDay]));
	}

	stacket.clear();
	int maxLength = 1;

	stacket.emplace(0, 0);
	for (int iDay = 0; iDay < days; iDay++)
	{
		std::set<Seq>::iterator prev = stacket.lower_bound(Seq(temp[iDay] + maxOffset, 1));
		prev--;
		maxLength = std::max(maxLength, prev->size + lds[iDay]);
		insert(Seq(temp[iDay], lis[iDay]));
	}

	std::cout << maxLength << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 372 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 372 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 4676 KB Output is correct
2 Correct 398 ms 4728 KB Output is correct
3 Correct 394 ms 4700 KB Output is correct
4 Correct 392 ms 4696 KB Output is correct
5 Correct 394 ms 8744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 1400 KB Output is correct
2 Correct 90 ms 1372 KB Output is correct
3 Correct 89 ms 1404 KB Output is correct
4 Correct 64 ms 2424 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 71 ms 2424 KB Output is correct
7 Correct 64 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 2552 KB Output is correct
2 Correct 180 ms 2524 KB Output is correct
3 Correct 381 ms 4652 KB Output is correct
4 Correct 399 ms 8696 KB Output is correct
5 Correct 200 ms 4472 KB Output is correct
6 Correct 294 ms 8188 KB Output is correct
7 Correct 260 ms 9000 KB Output is correct
8 Correct 132 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 372 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 392 ms 4676 KB Output is correct
28 Correct 398 ms 4728 KB Output is correct
29 Correct 394 ms 4700 KB Output is correct
30 Correct 392 ms 4696 KB Output is correct
31 Correct 394 ms 8744 KB Output is correct
32 Correct 89 ms 1400 KB Output is correct
33 Correct 90 ms 1372 KB Output is correct
34 Correct 89 ms 1404 KB Output is correct
35 Correct 64 ms 2424 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 71 ms 2424 KB Output is correct
38 Correct 64 ms 1528 KB Output is correct
39 Correct 180 ms 2552 KB Output is correct
40 Correct 180 ms 2524 KB Output is correct
41 Correct 381 ms 4652 KB Output is correct
42 Correct 399 ms 8696 KB Output is correct
43 Correct 200 ms 4472 KB Output is correct
44 Correct 294 ms 8188 KB Output is correct
45 Correct 260 ms 9000 KB Output is correct
46 Correct 132 ms 2552 KB Output is correct
47 Correct 187 ms 2644 KB Output is correct
48 Correct 188 ms 2576 KB Output is correct
49 Correct 403 ms 4876 KB Output is correct
50 Correct 396 ms 8656 KB Output is correct
51 Correct 386 ms 7708 KB Output is correct
52 Correct 503 ms 8824 KB Output is correct
53 Correct 343 ms 8656 KB Output is correct
54 Correct 292 ms 9432 KB Output is correct
55 Correct 284 ms 4864 KB Output is correct