Submission #864304

#TimeUsernameProblemLanguageResultExecution timeMemory
864304vjudge1Financial Report (JOI21_financial)C++17
45 / 100
4072 ms450168 KiB
#include <bits/stdc++.h> using namespace std; int n, p; vector<int> wl, wr; vector<vector<int> > dp; void upd(int j, int i, int x) { dp[i][j] = x; while (i > 1) { dp[i >> 1][j] = min(dp[i][j], dp[i ^ 1][j]); i >>= 1; } return; } int qmin(int j, int l, int r) { int an = 1000000001; while (l < r) { if (l & 1) { an = min(an, dp[l][j]); l++; } l >>= 1; if (r & 1) { r--; an = min(an, dp[r][j]); } r >>= 1; } return an; } int main() { int d, i; cin >> n >> d; vector<int> v(n); for (i = 0; i < n; i++) cin >> v[i]; if (n < 7001) { int j, k, m = 0; p = n; while (p != (p & -p)) p++; dp.resize(2 * p); wl.resize(2 * p); wr.resize(2 * p); for (i = p; i < 2 * p; i++) { dp[i].resize(n); for (j = 0; j < n; j++) dp[i][j] = 1000000001; wl[i] = i; wr[i] = i + 1; } for (i = p - 1; i >= 0; i--) { dp[i].resize(n); for (j = 0; j < n; j++) dp[i][j] = 1000000001; wl[i] = wl[2 * i]; wr[i] = wr[2 * i + 1]; } for (i = p; i < p + n; i++) { for (j = 0; j < n; j++) { if (j) { upd(j, i, 1000000001); k = qmin(j, max(p, i - d), i); upd(j, i, min(dp[i][j], k)); k = qmin(j - 1, max(p, i - d), i); if (k < v[i - p]) upd(j, i, min(dp[i][j], k)); } else upd(j, i, v[i - p]); upd(j, i, max(dp[i][j], v[i - p])); if (i == p + n - 1 && dp[i][j] < 1000000001) m = j; } } cout << m + 1; } else if (d == n) { vector<int> li = {v[0]}; for (i = 1; i < n; i++) { int hi = li.size(), lo = -1, md; while (hi - lo > 1) { md = (hi + lo) / 2; if (li[md] < v[i]) lo = md; else hi = md; } if (hi < li.size()) li[hi] = v[i]; else li.push_back(v[i]); } cout << li.size(); } else if (d == 1) { v.push_back(1000000001); vector<int> ne(n + 1, n), st = {n}, ml(n + 1, 0); int m = 0; for (i = n - 1; i >= 0; i--) { while (v[i] >= v[st.back()]) st.pop_back(); ne[i] = st.back(); ml[i] = ml[ne[i]] + 1; m = max(m, ml[i]); st.push_back(i); } cout << m; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:104:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |             if (hi < li.size())
      |                 ~~~^~~~~~~~~~~
#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...