Submission #827573

#TimeUsernameProblemLanguageResultExecution timeMemory
827573mgl_diamondGlobal Warming (CEOI18_glo)C++17
58 / 100
57 ms5308 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; #define foru(i, l, r) for(int i=(l); i<=(r); ++i) #define ford(i, l, r) for(int i=(l); i>=(r); --i) #define fore(x, v) for(auto &x : v) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define fi first #define se second #define file "input" void setIO(string name="") { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(file".in", "r")) { freopen(file".in", "r", stdin); freopen(file".out", "w", stdout); } } const int N = 2e5+5; int n, x, a[N], lb[N], rb[N], dp[N]; int main() { setIO(); cin >> n >> x; foru(i, 1, n) cin >> a[i]; a[n+1] = (int)1e9; memset(dp, 0x3f, sizeof(dp)); foru(i, 1, n) { int pos = 0; for(int z=n>>1; z>=1; z>>=1) while (pos+z <= n && dp[pos+z] < a[i]) pos += z; dp[pos+1] = a[i]; for(int z=n>>1; z>=1; z>>=1) while (lb[i]+z <= n && dp[lb[i]+z] < a[i+1]+x) lb[i] += z; } memset(dp, -0x3f, sizeof(dp)); ford(i, n, 1) { int pos = 0; for(int z=n>>1; z>=1; z>>=1) while (pos+z <= n && dp[pos+z] > a[i]) pos += z; dp[pos+1] = a[i]; rb[i] = pos+1; } int ans = 0; foru(i, 1, n) ans = max(ans, lb[i] + rb[i+1]); cout << ans; }

Compilation message (stderr)

glo.cpp: In function 'void setIO(std::string)':
glo.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen(file".in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen(file".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...