Submission #1268768

#TimeUsernameProblemLanguageResultExecution timeMemory
1268768quangminh412Global Warming (CEOI18_glo)C++17
100 / 100
342 ms34808 KiB
/* Ben Watson Quang Minh MasterDDDDD */ #include <bits/stdc++.h> using namespace std; #define ll long long const string name = "stellar"; void solve(); signed main() { if (fopen((name + ".inp").c_str(), "r")) { freopen((name + ".inp").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } // main program const int maxn = 2e5 + 1; struct FenwickTree { vector<int> bits; int n; FenwickTree(int n) : n(n) { bits.resize(n + 1, 0); } void reset() { for (int i = 0; i <= n; i++) bits[i] = 0; } void update(int pos, int val) { for (; pos <= n; pos += (pos & (-pos))) bits[pos] = max(bits[pos], val); } int query(int pos) { int res = 0; for (; pos > 0; pos -= (pos & (-pos))) res = max(res, bits[pos]); return res; } }; unordered_map<int, int> mp; int a[maxn], L[maxn], R[maxn], cmp[maxn]; vector<int> proc; int n, x, m; void solve() { cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; proc.push_back(a[i]); proc.push_back(a[i] - x); proc.push_back(a[i] + x); } m = 0; sort(proc.begin(), proc.end()); for (int x : proc) if (mp[x] == 0) mp[x] = ++m; for (int i = 1; i <= n; i++) cmp[i] = mp[a[i]]; FenwickTree bit_L(m); for (int i = 1; i <= n; i++) { L[i] = 1 + bit_L.query(cmp[i] - 1); bit_L.update(cmp[i], L[i]); } FenwickTree bit_R(m); for (int i = n; i > 0; i--) { R[i] = 1; if (cmp[i] != m) R[i] = 1 + bit_R.query(m + 1 - (cmp[i] + 1)); bit_R.update(m + 1 - cmp[i], R[i]); } int res = 0; bit_L.reset(); for (int i = 1; i <= n; i++) { int tmp = 1 + bit_L.query(cmp[i] - 1); res = max(res, R[i] + bit_L.query(mp[a[i] + x] - 1)); bit_L.update(cmp[i], tmp); } bit_R.reset(); for (int i = n; i > 0; i--) { int tmp = 1; if (cmp[i] != m) tmp = 1 + bit_R.query(m + 1 - (cmp[i] + 1)); int pos = upper_bound(proc.begin(), proc.end(), a[i] - x) - proc.begin(); if (pos != (int)proc.size()) res = max(res, L[i] + bit_R.query(m + 1 - mp[proc[pos]])); bit_R.update(m + 1 - cmp[i], tmp); } cout << res << '\n'; }

Compilation message (stderr)

glo.cpp: In function 'int main()':
glo.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((name + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((name + ".out").c_str(), "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...