Submission #95188

# Submission time Handle Problem Language Result Execution time Memory
95188 2019-01-28T11:24:22 Z Retro3014 Global Warming (CEOI18_glo) C++17
100 / 100
73 ms 4712 KB
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>

using namespace std;
#define MAX_N 200000


int N, D;
vector<int> v;
vector<int> stack;
int num[MAX_N+1];
int ans = 0;

int main(){
	scanf("%d %d", &N, &D);
	int x;
	for(int i=0; i<N; i++){
		scanf("%d", &x); v.push_back(x);
	}
	for(int i=v.size()-1; i>=0; i--){
		if(stack.empty()){
			num[i] = 1;
			stack.push_back(v[i]);
		}else{
			if(stack.back()>v[i]){
				stack.push_back(v[i]);
				num[i] = stack.size();
			}else{
				int s = 0, e = stack.size()-1, m;
				while(s<e){
					m = (s+e)/2;
					if(stack[m]>v[i])	s = m+1;
					else	e = m;
				}
				num[i] = s+1;
				stack[s] = v[i];
			}
		}
	}
	stack.clear();
	for(int i=0; i<v.size(); i++){
		int s = 0, e = stack.size(), m;
		while(s<e){
			m=(s+e)/2;
			if(stack[m]<v[i]+D) s = m+1;
			else	e = m;
		}
		//cout<<i<<" "<<s<<" "<<num[i]<<endl;
		ans = max(ans, s+num[i]);
		if(stack.empty()){
			stack.push_back(v[i]);
		}else{
			if(stack.back()<v[i])	stack.push_back(v[i]);
			else{
				s = 0; e = stack.size()-1;
				while(s<e){
					m = (s+e)/2;
					if(stack[m]<v[i])	s = m+1;
					else	e = m;
				}
				stack[s] = v[i];
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
glo.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &D);
  ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x); v.push_back(x);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 2032 KB Output is correct
2 Correct 73 ms 2024 KB Output is correct
3 Correct 68 ms 2024 KB Output is correct
4 Correct 69 ms 2024 KB Output is correct
5 Correct 37 ms 2792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 884 KB Output is correct
2 Correct 18 ms 944 KB Output is correct
3 Correct 17 ms 884 KB Output is correct
4 Correct 10 ms 1008 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 10 ms 1268 KB Output is correct
7 Correct 15 ms 1396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1264 KB Output is correct
2 Correct 31 ms 2164 KB Output is correct
3 Correct 62 ms 3948 KB Output is correct
4 Correct 38 ms 3944 KB Output is correct
5 Correct 19 ms 2132 KB Output is correct
6 Correct 32 ms 3816 KB Output is correct
7 Correct 33 ms 4584 KB Output is correct
8 Correct 27 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 69 ms 2032 KB Output is correct
28 Correct 73 ms 2024 KB Output is correct
29 Correct 68 ms 2024 KB Output is correct
30 Correct 69 ms 2024 KB Output is correct
31 Correct 37 ms 2792 KB Output is correct
32 Correct 17 ms 884 KB Output is correct
33 Correct 18 ms 944 KB Output is correct
34 Correct 17 ms 884 KB Output is correct
35 Correct 10 ms 1008 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 10 ms 1268 KB Output is correct
38 Correct 15 ms 1396 KB Output is correct
39 Correct 30 ms 1264 KB Output is correct
40 Correct 31 ms 2164 KB Output is correct
41 Correct 62 ms 3948 KB Output is correct
42 Correct 38 ms 3944 KB Output is correct
43 Correct 19 ms 2132 KB Output is correct
44 Correct 32 ms 3816 KB Output is correct
45 Correct 33 ms 4584 KB Output is correct
46 Correct 27 ms 2156 KB Output is correct
47 Correct 34 ms 2164 KB Output is correct
48 Correct 36 ms 2164 KB Output is correct
49 Correct 68 ms 3916 KB Output is correct
50 Correct 38 ms 3948 KB Output is correct
51 Correct 30 ms 3304 KB Output is correct
52 Correct 36 ms 4124 KB Output is correct
53 Correct 34 ms 4076 KB Output is correct
54 Correct 34 ms 4712 KB Output is correct
55 Correct 56 ms 3948 KB Output is correct