Submission #1284783

#TimeUsernameProblemLanguageResultExecution timeMemory
1284783celesGlobal Warming (CEOI18_glo)C++20
100 / 100
85 ms5452 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end()) const int N = 3e5 + 5; int n, x; int a[N], c[N], val[N]; vector<int> b; int fenpre[N], fensuf[N]; void update(int bit[], int u, int val) { while (u < N) { bit[u] = max(bit[u], val); u += u & -u; } } int get(int bit[], int u) { int res = 0; while (u) { res = max(res, bit[u]); u -= u & -u; } return res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "bseq" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".ans", "w", stdout); } if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.ans", "w", stdout); } cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; c[i] = a[i]; b.pb(a[i]); } b.pb(0); Unique(b); for (int i = 1; i <= n; i++) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (int i = 1; i <= n; i++) { ll p = get(fenpre, a[i] - 1) + 1; val[i] = p; update(fenpre, a[i], p); } int res = 0; for (int i = n; i >= 1; i--) { int p = get(fensuf, N - 3 - a[i] - 1) + 1; int low = max(0, c[i] - x); int idx = upper_bound(all(b), low) - b.begin() - 1; res = max(res, val[i] + get(fensuf, N - 3 - idx - 1)); update(fensuf, N - 3 - a[i], p); } cout<<res; cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\n"; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(task".ans", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("task.ans", "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...