Submission #1279039

#TimeUsernameProblemLanguageResultExecution timeMemory
1279039swishy123Rabbit Carrot (LMIO19_triusis)C++20
100 / 100
69 ms6696 KiB
#include <bits/stdc++.h> #define ll long long const int inf = 1e9; using namespace std; struct SegmentTreeFast{ vector<int> a; int defv; int n; SegmentTreeFast(int n, int defv) : n(n), defv(defv){ a = vector<int>(2 * n, defv); } int cmb(int a, int b){ return max(a, b); } void build(){ for (int i = n - 1; i > 0; --i) a[i] = cmb(a[i << 1], a[i << 1 | 1]); } void update(int i, int v){ int val = a[i + n]; for (a[i += n] = cmb(v, val); i > 1; i >>= 1) a[i >> 1] = cmb(a[i], a[i ^ 1]); } int get(int l, int r){ r++; int res = defv; for (l += n, r += n; l < r; l >>= 1, r >>= 1){ if (l&1) res = cmb(res, a[l++]); if (r&1) res = cmb(res, a[--r]); } return res; } }; int get(vector<ll> a, int n, int m){ for (int i = 0; i < n; i++) a[i] = a[i] - (ll)i * m; auto v = a; sort(v.begin(), v.end()); SegmentTreeFast st(n, -1e9); int pos = lower_bound(v.begin(), v.end(), a[0]) - v.begin(); st.update(pos, 1); for (int i = 1; i < n; i++){ pos = lower_bound(v.begin(), v.end(), a[i]) - v.begin(); int val = st.get(pos, n - 1); st.update(pos, val + 1); } int res = st.get(0, n - 1); return n - res; } void solve(){ ll n, m; cin >> n >> m; vector<ll> a(n, 0); for (int i = 0; i < n; i++) cin >> a[i]; int res = n; if (a[0] <= m) res = min(res, get(a, n, m)); a[0] = m; res = min(res, get(a, n, m) + 1); cout << res; } /* -1 3 -1 1 0 -1 11 3 0 1 0 0 1 0 3 2 0 1 3 2 */ int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ifstream("input.txt").good()){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int t; t = 1; while (t--){ solve(); cout << '\n'; } }

Compilation message (stderr)

triusis.cpp: In function 'int main()':
triusis.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen("output.txt", "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...