제출 #742741

#제출 시각아이디문제언어결과실행 시간메모리
742741ToniBFinancial Report (JOI21_financial)C++17
53 / 100
759 ms36584 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 2; const int OFF = 1 << 20; int n, d, a[MAXN], ans, dp[7005]; int tour[OFF]; priority_queue<int, vector<int>, greater<int> > pq; multiset<int> ms; vector<int> cmp; map<int, int> um; int f(int x, int l, int r, int ql, int qr){ if(ql <= l && r <= qr) return tour[x]; if(ql > r || l > qr) return 0; int mid = (l + r) >> 1; return max(f(x * 2 + 1, l, mid, ql, qr), f(x * 2 + 2, mid + 1, r, ql, qr)); } void upd(int x, int l, int r, int i, int val){ if(l > i || r < i) return ; if(l == r){ tour[x] = val; return ; } int mid = (l + r) >> 1; upd(x * 2 + 1, l, mid, i, val); upd(x * 2 + 2, mid + 1, r, i, val); tour[x] = max(tour[x * 2 + 1], tour[x * 2 + 2]); } int main(){ cin >> n >> d; for(int i = 0; i < n; ++i){ cin >> a[i]; cmp.push_back(a[i]); } sort(cmp.begin(), cmp.end()); cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end()); for(int i = 0; i < (int)cmp.size(); ++i) um[cmp[i]] = i; for(int i = 0; i < n; ++i) a[i] = um[a[i]]; if(n <= 7005){ for(int i = 0; i < n; ++i){ dp[i] = max(dp[i], 1); int prv_less, k = n - 1; for(int j = i; j < n; ++j){ if(a[j] <= a[i]) prv_less = j; if(j - prv_less == d){ k = j; break; } } for(int j = i + 1; j <= k; ++j){ if(a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } ans = max(ans, dp[i]); } cout << ans << "\n"; return 0; } for(int i = 0; i < n; ++i){ int x = 0; if(a[i]) x = f(0, 0, n - 1, 0, a[i] - 1); upd(0, 0, n - 1, a[i], x + 1); ans = max(ans, x + 1); ms.insert(a[i]); pq.push(a[i]); if(i >= d){ ms.erase(ms.find(a[i - d])); int mini = *ms.begin(); while(!pq.empty() && pq.top() < mini){ int x = pq.top(); upd(0, 0, n - 1, x, 0); pq.pop(); } } } cout << ans; return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:50:10: warning: 'prv_less' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |     if(j - prv_less == d){
      |        ~~^~~~~~~~~~
#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...