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