Submission #1280779

#TimeUsernameProblemLanguageResultExecution timeMemory
1280779vuquangsangGlobal Warming (CEOI18_glo)C++20
100 / 100
43 ms3580 KiB
#include <bits/stdc++.h> using namespace std; #define el "\n" #define FOR(i,a,b) for(int i = (a), _b = (b); i <= _b; i++) #define FORD(i,a,b) for(int i = (a), _b = (b); i >= _b; i--) #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define lg(x) __lg(x) #define alla(a,n) a+1,a+n+1 #define ll long long template <class T> bool maxi(T &x, T y) { if(x < y) { x = y ; return true ;} return false;} template <class T> bool mini(T &x, T y) { if(x > y) { x = y ; return true ;} return false;} const int N = 2e5 + 2; const int INF = 1e9 + 2; int n, a[N], lim; void inp() { cin >> n >> lim; FOR(i, 1, n) cin >> a[i]; } /* Try your best No regrets */ namespace subtask_3 { int temp[N]; void slv() { int ans = 0; for(int i = 1; i <= n; i++) { a[i] -= lim; for(int j = 1; j <= n; j++) temp[j] = INF; for(int j = 1; j <= n; j++) { int pos = lower_bound(temp + 1, temp + n + 1, a[j]) - temp; maxi(ans, pos); temp[pos] = a[j]; } } cout << ans; } } namespace subtask_4 { int temp[N], dp[N]; void slv() { FOR(i, 1, n) temp[i] = INF; int ans = 0; FOR(i, 1, n) { int pos = lower_bound(temp + 1, temp + n + 1, a[i]) - temp; dp[i] = pos; temp[pos] = a[i]; maxi(ans, pos); } cout << ans; } } namespace subtask_7 { int Left[N], Right[N]; int res = 0; int temp[N]; void prepare() { FOR(i, 1, n) temp[i] = INF; int ans = 0; for(int i = 1; i <= n; i++) { int pos = lower_bound(temp + 1, temp + n + 1, a[i]) - temp; temp[pos] = a[i]; Left[i] = pos; } FOR(i, 1, n) temp[i] = INF; ans = 0; for(int i = n; i >= 1; i--) { int pos = lower_bound(temp + 1, temp + n + 1, - a[i] + lim) - temp; Right[i] = pos; pos = lower_bound(temp + 1, temp + n + 1, - a[i]) - temp; temp[pos] = - a[i]; } } void slv() { prepare(); int ans = 0; FOR(i, 1, n) { maxi(ans, Left[i] + Right[i] - 1); } cout << ans; } } /* Code slowly, think carefully */ main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define __Azul__ "glo" if(fopen(__Azul__".inp", "r")) { freopen(__Azul__".inp", "r", stdin); freopen(__Azul__".out", "w", stdout); } bool qs = 0; int T = 1; if(qs) cin >> T; while(T--) { inp(); subtask_7::slv(); // if(!lim) subtask_4::slv(); // else if(n <= 1000) subtask_3::slv(); // else subtask_7::slv(); } cerr << "\nTime" << 0.001 * clock() << "s "; return 0; }

Compilation message (stderr)

glo.cpp:116:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  116 | main()
      | ^~~~
glo.cpp: In function 'int main()':
glo.cpp:122:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |         freopen(__Azul__".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |         freopen(__Azul__".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...