답안 #384864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384864 2021-04-02T13:55:20 Z mariowong Global Warming (CEOI18_glo) C++14
100 / 100
500 ms 4708 KB
#include <bits/stdc++.h>

using namespace std;

int n,d,a[200005],now,ans_used[200005],ans[200005],anss,pt;
vector <pair<int,int>  > v1,v2;
void solve(int l,int r){
	if (l == r){
		ans[l]=max(ans[l],1);
		ans_used[l]=max(ans_used[l],1);
	}
	else
	{
		int mid=(l+r)/2;
		solve(l,mid);
		v1.clear(); v2.clear();
		for (int i=l;i<=mid;i++){
			v1.push_back(make_pair(a[i],ans_used[i]));
		}
		for (int i=mid+1;i<=r;i++){
			v2.push_back(make_pair(a[i],i));
		}
		sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end());
		pt=0; now=0;
		for (int i=0;i<v2.size();i++){
			while (pt < (int)v1.size() && v1[pt].first < v2[i].first){
				now=max(now,v1[pt].second);
				pt++;
			}
			ans_used[v2[i].second]=max(ans_used[v2[i].second],now+1);
		}
		v1.clear(); v2.clear();
		for (int i=l;i<=mid;i++){
			v1.push_back(make_pair(a[i],ans[i]));
		}
		for (int i=mid+1;i<=r;i++){
			v2.push_back(make_pair(a[i],i));
		}
		sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end());
		pt=0; now=0; 
		for (int i=0;i<v2.size();i++){
			while (pt < (int)v1.size() && v1[pt].first < v2[i].first){
				now=max(now,v1[pt].second);
				pt++;
			}
			ans[v2[i].second]=max(ans[v2[i].second],now+1);
		}
		pt=0; now=0;
		for (int i=0;i<v2.size();i++){
			while (pt < (int)v1.size() && v1[pt].first-d < v2[i].first){
				now=max(now,v1[pt].second);
				pt++;
			}
			ans_used[v2[i].second]=max(ans_used[v2[i].second],now+1);
		}
		solve(mid+1,r);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> d;
	for (int i=1;i<=n;i++){
		cin >> a[i];
	}
	solve(1,n);
	for (int i=1;i<=n;i++){
		anss=max(anss,max(ans_used[i],ans[i]));
	}
	cout << anss << "\n";
	return 0;
}

Compilation message

glo.cpp: In function 'void solve(int, int)':
glo.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for (int i=0;i<v2.size();i++){
      |                ~^~~~~~~~~~
glo.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int i=0;i<v2.size();i++){
      |                ~^~~~~~~~~~
glo.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int i=0;i<v2.size();i++){
      |                ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 481 ms 4440 KB Output is correct
2 Correct 476 ms 4440 KB Output is correct
3 Correct 488 ms 4532 KB Output is correct
4 Correct 474 ms 4440 KB Output is correct
5 Correct 360 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 1512 KB Output is correct
2 Correct 110 ms 1512 KB Output is correct
3 Correct 100 ms 1512 KB Output is correct
4 Correct 75 ms 1512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 51 ms 1512 KB Output is correct
7 Correct 82 ms 1512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 2528 KB Output is correct
2 Correct 211 ms 2532 KB Output is correct
3 Correct 460 ms 4568 KB Output is correct
4 Correct 375 ms 4568 KB Output is correct
5 Correct 113 ms 2528 KB Output is correct
6 Correct 176 ms 4312 KB Output is correct
7 Correct 179 ms 4312 KB Output is correct
8 Correct 175 ms 2784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 481 ms 4440 KB Output is correct
28 Correct 476 ms 4440 KB Output is correct
29 Correct 488 ms 4532 KB Output is correct
30 Correct 474 ms 4440 KB Output is correct
31 Correct 360 ms 4440 KB Output is correct
32 Correct 110 ms 1512 KB Output is correct
33 Correct 110 ms 1512 KB Output is correct
34 Correct 100 ms 1512 KB Output is correct
35 Correct 75 ms 1512 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 51 ms 1512 KB Output is correct
38 Correct 82 ms 1512 KB Output is correct
39 Correct 209 ms 2528 KB Output is correct
40 Correct 211 ms 2532 KB Output is correct
41 Correct 460 ms 4568 KB Output is correct
42 Correct 375 ms 4568 KB Output is correct
43 Correct 113 ms 2528 KB Output is correct
44 Correct 176 ms 4312 KB Output is correct
45 Correct 179 ms 4312 KB Output is correct
46 Correct 175 ms 2784 KB Output is correct
47 Correct 217 ms 2656 KB Output is correct
48 Correct 220 ms 2656 KB Output is correct
49 Correct 500 ms 4708 KB Output is correct
50 Correct 355 ms 4568 KB Output is correct
51 Correct 145 ms 3544 KB Output is correct
52 Correct 266 ms 4440 KB Output is correct
53 Correct 184 ms 4440 KB Output is correct
54 Correct 187 ms 4568 KB Output is correct
55 Correct 394 ms 4440 KB Output is correct