版本比较
8.17
正文
增加 19 行删除 24 行
157 行未改动全部展开158159160161162163162163164165166167168168169170171171172172173174175174175176176177178179180181182183178179180184185182186184185186187188189190191192193187188189190196191192193194195137 行未改动全部展开33333433533634233733833934034111 行未改动157 行未改动全部展开#### 考场代码```cpp line-numbers#include <bits/stdc++.h>using namespace std ;long long n , k , a[1000005] ;deque <long long> minn , maxn ;long long n , a[300005] , l[300005] , r[300005] , maxn ;stack <long long> stk ;int main() { ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; cin >> n >> k ; cin >> n ; fill(r + 1 , r + n + 1 , n + 1) ; for(int i = 1 ; i <= n ; i ++) { cin >> a[i] ; while(minn.size() && a[minn.back()] >= a[i]) { minn.pop_back() ; while(stk.size() && a[stk.top()] > a[i]) { r[stk.top()] = i ; stk.pop() ; } minn.push_back(i) ; if(i - minn.front() >= k) { minn.pop_front() ; stk.push(i) ; } stk = stack <long long> () ; for(int i = n ; i >= 1 ; i --) { while(stk.size() && a[stk.top()] > a[i]) { l[stk.top()] = i ; stk.pop() ; } if(i >= k) { cout << a[minn.front()] << " " ; } stk.push(i) ; } cout << "\n" ; for(int i = 1 ; i <= n ; i ++) { while(maxn.size() && a[maxn.back()] <= a[i]) { maxn.pop_back() ; } maxn.push_back(i) ; if(i - maxn.front() >= k) { maxn.pop_front() ; } if(i >= k) { cout << a[maxn.front()] << " " ; } maxn = max(maxn , (r[i] - l[i] - 1) * (a[i])) ; } cout << maxn ; return 0 ;}} ```#### 赛后题解我是对的#### 复杂度137 行未改动全部展开```#### 赛后题解我是对的#### 复杂度- 时间复杂度:$O(n\times\log_2 10^5)$- 时间复杂度:$O(n\log_2 n)$- 空间复杂度:$O(n)$#### 补题代码我是对的#### 本题总结11 行未改动