Submission #1016979

#TimeUsernameProblemLanguageResultExecution timeMemory
1016979NguyenPhucThangRabbit Carrot (LMIO19_triusis)C++14
0 / 100
18 ms24004 KiB
#include <bits/stdc++.h> #define forr(i, a, b) for (int i = a; i <= b; i++) #define ford(i, a, b) for (int i = a; i >= b; i--) #define fi first #define se second #define pb push_back #define all(v) v.begin(), v.end() #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vii vector<pii> #define file "test" using namespace std; const int base = 31; const ll mod = 1e9 + 7; const ll oo = 1e18; const int N = 2e5 + 5; const int V = 2e5; int dp[N], st[4*N]; ll h[N], t[N]; vector<ll> nen; void update(int id, int l, int r, int i, int v){ if (i < l || r < i) return; if (l == r){ st[id] = max(st[id], v); return; } int mid = (l + r) >> 1; update(2 * id, l, mid, i, v), update(2 * id + 1, mid + 1, r, i, v); st[id] = max(st[2 * id], st[2 * id + 1]); } int get(int id, int l, int r, int u, int v){ if (v < l || r < u) return 0; if (u <= l && r <= v) return st[id]; int mid = (l + r) >> 1; return max(get(2 * id, l, mid, u, v), get(2 * id + 1, mid + 1, r, u, v)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); #endif int n, M; cin >> n >> M; forr(i, 1, n){ cin >> h[i]; t[i] = h[i] - M*i; nen.pb(t[i]); } nen.pb(0); sort(all(nen)); nen.resize(unique(all(nen)) - nen.begin()); forr(i,0,n) t[i] = lower_bound(all(nen), t[i]) - nen.begin() - 1; dp[0] = 1; update(1, 1, V, t[0], dp[0]); forr(i, 1, n){ int f = get(1, 1, V, t[i], V); if (f) { dp[i] = f + 1; update(1, 1, V, t[i], dp[i]); } } int res = 0; forr(i, 0, n) res = max(res, dp[i]); cout << n - res + 1; return 0; }

Compilation message (stderr)

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