Submission #963179

# Submission time Handle Problem Language Result Execution time Memory
963179 2024-04-14T16:34:25 Z noobcodur Global Warming (CEOI18_glo) C++14
100 / 100
48 ms 9440 KB
#include<bits/stdc++.h>
using namespace std;

using ld = long double;

#define int long long
#define pii pair<int,int>
#define forn(i,j) for(int i = 0; i < j; ++i)
#define forrange(i,j,k) for(int i = j; i < k; ++i)
#define vi vector<int>
#define vpii vector<pii>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

const int MOD = 1e9+7; const int INF = 1e17+1; const int maxN = 2e5+1;

void setIO(string name){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	if(!name.empty()){
		freopen((name + ".in").c_str(),"r",stdin);
		freopen((name + ".out").c_str(),"w",stdout);
	}
}

int l[maxN],r[maxN];

signed main(){
	setIO("");
	int n,x; cin >> n >> x;
	vi a(n),b(n);

	forn(i,n){
		cin >> a[i];
		b[i] = -a[i];
	}

	vi dp;

	forn(i,n){
		if(dp.empty() || dp.back() < a[i]){
			dp.pb(a[i]);
			l[i] = dp.size();
			continue;
		}

		int j = lower_bound(all(dp),a[i]) - dp.begin();
		dp[j] = a[i];
		l[i] = j+1;
	}

	dp.clear();

	for(int i = n-1; i >= 0; --i){
		int j = lower_bound(all(dp),b[i]+x) - dp.begin();
		r[i] = j+1;	

		j = lower_bound(all(dp),b[i]) - dp.begin();

		if(j == dp.size()){
			dp.pb(b[i]);
		}

		else{
			dp[j] = b[i];
		}
	}

	int res = 0;

	forn(i,n){
		res = max(res,l[i]+r[i]-1);
	}

	cout << res << endl;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:63:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   if(j == dp.size()){
      |      ~~^~~~~~~~~~~~
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen((name + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen((name + ".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2520 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2536 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2400 KB Output is correct
25 Correct 1 ms 2512 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 8576 KB Output is correct
2 Correct 46 ms 8492 KB Output is correct
3 Correct 48 ms 8636 KB Output is correct
4 Correct 46 ms 8732 KB Output is correct
5 Correct 26 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3936 KB Output is correct
2 Correct 12 ms 3932 KB Output is correct
3 Correct 11 ms 3932 KB Output is correct
4 Correct 6 ms 3940 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 9 ms 4060 KB Output is correct
7 Correct 9 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 5312 KB Output is correct
2 Correct 21 ms 5340 KB Output is correct
3 Correct 39 ms 8480 KB Output is correct
4 Correct 21 ms 8916 KB Output is correct
5 Correct 11 ms 5364 KB Output is correct
6 Correct 18 ms 8400 KB Output is correct
7 Correct 23 ms 9064 KB Output is correct
8 Correct 17 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2520 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2536 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2400 KB Output is correct
25 Correct 1 ms 2512 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 46 ms 8576 KB Output is correct
28 Correct 46 ms 8492 KB Output is correct
29 Correct 48 ms 8636 KB Output is correct
30 Correct 46 ms 8732 KB Output is correct
31 Correct 26 ms 8568 KB Output is correct
32 Correct 11 ms 3936 KB Output is correct
33 Correct 12 ms 3932 KB Output is correct
34 Correct 11 ms 3932 KB Output is correct
35 Correct 6 ms 3940 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 9 ms 4060 KB Output is correct
38 Correct 9 ms 3932 KB Output is correct
39 Correct 23 ms 5312 KB Output is correct
40 Correct 21 ms 5340 KB Output is correct
41 Correct 39 ms 8480 KB Output is correct
42 Correct 21 ms 8916 KB Output is correct
43 Correct 11 ms 5364 KB Output is correct
44 Correct 18 ms 8400 KB Output is correct
45 Correct 23 ms 9064 KB Output is correct
46 Correct 17 ms 5248 KB Output is correct
47 Correct 23 ms 5188 KB Output is correct
48 Correct 23 ms 5436 KB Output is correct
49 Correct 45 ms 8484 KB Output is correct
50 Correct 22 ms 8652 KB Output is correct
51 Correct 21 ms 7160 KB Output is correct
52 Correct 22 ms 8712 KB Output is correct
53 Correct 20 ms 8836 KB Output is correct
54 Correct 26 ms 9440 KB Output is correct
55 Correct 36 ms 8540 KB Output is correct