Submission #978137

#TimeUsernameProblemLanguageResultExecution timeMemory
978137IsamGlobal Warming (CEOI18_glo)C++17
100 / 100
48 ms5488 KiB
#include<bits/stdc++.h>
using namespace std;

constexpr int sz = 2e5 + 5;
constexpr int inf = 1E9 + 7;
 
int n, x, a[sz], f[sz], f2[sz], num, num2, p[sz], p2[sz], ans;
 
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	
	cin >> n >> x;
	
	for(register int i = 1; i <= n; ++i) cin >> a[i];
	
	for(register int i = 1; i <= n; ++i){
		
		if(a[i] > f[num]){
			
			f[++num] = a[i];
			
			p[i] = num;
		
		}else{
			
			p[i] = lower_bound(f + 1, f + num + 1, a[i]) - f;
			
			f[p[i]] = a[i];
			
		}
		
	}
	
	f2[0] = inf;
	
	for(register int i = n; i >= 1; --i){
		
		p2[i] = lower_bound(f2 + 1, f2 + num2 + 1, a[i] - x, greater<int>()) - f2;
		
		if(a[i] < f2[num2]){
			
			f2[++num2] = a[i];
			
			p2[i] = num2;
		
		}else{
			
			*lower_bound(f2 + 1, f2 + num2 + 1, a[i], greater<int>()) = a[i];
			
			
		}
		
		
		
	}
	
	
	for(register int i = 1; i <= n; ++i) ans = max(ans, p[i] + p2[i] - 1);
	
	cout << ans << '\n';
	
	
	
	
}

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:14:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 |  for(register int i = 1; i <= n; ++i) cin >> a[i];
      |                   ^
glo.cpp:16:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |  for(register int i = 1; i <= n; ++i){
      |                   ^
glo.cpp:36:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   36 |  for(register int i = n; i >= 1; --i){
      |                   ^
glo.cpp:58:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   58 |  for(register int i = 1; i <= n; ++i) ans = max(ans, p[i] + p2[i] - 1);
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...