Cod sursa(job #2959488)

Utilizator OvidRata Ovidiu Ovid Data 31 decembrie 2022 14:39:56
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
//#define int ll

ifstream fin("secventa.in"); ofstream fout("secventa.out");
#define cin fin
#define cout fout

int t, n, m, k, a[500010], q, l, r;
int lt[500010], rt[500010];

int32_t main(){
    INIT
    cin>>n>>k;
    a[0]=-31000;
    for(int i=1; i<=n; i++){cin>>a[i]; int j; for(j=i-1; a[j]>=a[i]; j=lt[j]){}; lt[i]=j;    }
    a[n+1]=-31000;
    int mx=-31000, f=0, s=0;
    for(int i=n; i>=1; i--){
        int j;
        for(j=(i+1); a[j]>=a[i]; j=rt[j]){};
        rt[i]=j;
        int l=lt[i]+1, r=rt[i]-1;
        if( ((r-l+1)>=k) && (a[i]>=mx) ){
            f=l; s=max(min(r, l+k-1), i); mx=a[i];
        }
    }

    cout<<f<<" "<<s<<" "<<mx;
    return 0;
}