제출 #1277943

#제출 시각아이디문제언어결과실행 시간메모리
1277943wedonttalkanymoreFinancial Report (JOI21_financial)C++20
5 / 100
474 ms87304 KiB
#include <bits/stdc++.h> /* Brute to win */ using namespace std; using ll = long long; #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 3e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19; int n, D, a[N]; vector <int> comp; int dp[N]; struct ST { vector <int> st; multiset <int, greater <int> > s[4 * N]; ST (int _n) { st.assign(4 * (_n + 1), 0); } void update(int i, int l, int r, int pos, int val, int type) { if (l == r) { if (type == 1) s[i].insert(val); else { auto it = s[i].find(val); if (it != s[i].end()) s[i].erase(it); } if (s[i].size()) st[i] = *s[i].begin(); else st[i] = 0; return; } int mid = (l + r) / 2; if (pos <= mid) update(2 * i, l, mid, pos, val, type); else update(2 * i + 1, mid + 1, r, pos, val, type); st[i] = max(st[2 * i], st[2 * i + 1]); } int get(int i, int l, int r, int u, int v) { if (u > r || v < l) return 0; if (u <= l && r <= v) return st[i]; int mid = (l + r) / 2; return max(get(2 * i, l, mid, u, v), get(2 * i + 1, mid + 1, r, u, v)); } } st(N); signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n >> D; for (int i = 1; i <= n; i++) { cin >> a[i]; comp.push_back(a[i]); } sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for (int i = 1; i <= n; i++) { a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin() + 1; } int l = 1; for (int i = 1; i <= n; i++) { while(l < i - D) { st.update(1, 1, n, a[l], dp[l], -1); l++; } int val = st.get(1, 1, n, 1, a[i] - 1); dp[i] = val + 1; st.update(1, 1, n, a[i], dp[i], 1); } int ans = 0; // for (int i = 1; i <= n; i++) cout << dp[i] << ' '; // cout << '\n'; for (int i = n - D; i <= n; i++) ans = max(ans, dp[i]); cout << ans; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(".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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...