Cod sursa(job #1651220)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 12 martie 2016 18:45:53
Problema Secventa Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.84 kb
// Template v2
#define pb push_back
#define mp make_pair
#define first x
#define second y
#define l(x) x<<1
#define r(x) x<<1 | 1
#define P 73
#define MOD1 3000017
#define MOD2 3000541
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PKK;
// primes less than 100
const int PRIM[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const int CMAX = 10005;
const int MOD = 1000000007;
const int NMAX = 500005;
const short INF16 = 32000;
const int INF = int(1e9);
const LL INF64 = LL(1e18);
const LD EPS = 1e-9, PI = acos(-1.0);

char c[NMAX*100];
int A[NMAX];
int deq[NMAX], l, r, n, k, a, rsr, rsl;
LL rs;

void buffer()
{
    cin.get(c, NMAX*100);
    for(int i=0; c[i]; ++i)
    {
        int nr=0;
        bool sgn=false;

        if(isdigit(c[i])){
            if(c[i-1]=='-')
                sgn=true;
            while(isdigit(c[i]))
                nr=nr*10+c[i++]-'0';
            if(sgn)
                nr=-nr;
            A[++n]=nr;
        }
    }
}

void read()
{
    cin>>n>>k;
    cin.get();
    n=0;
    buffer();
    
    rs=-INF;
    cout<<"";
    for(int i=1; i<=n; ++i){
        cin>>A[i];
    }
    l=1; r=0;
    for(int i=1; i<=n; ++i)
    {
        while(l<=r && A[i]<=A[deq[r]])
            r--;
        deq[++r]=i;
        if(deq[l]==i-k)
            l++;
        
        if(i>=k && A[deq[l]]>rs){
            rs = A[deq[l]];
            rsl =i-k+1;
            rsr= i;
        }
    }
    cout<<rsl<<" "<<rsr<<" "<<rs;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cout << setprecision(16) << fixed;
    
    assert(freopen("secventa.in", "rt", stdin));
    assert(freopen("secventa.out", "wt", stdout));
    
    read();

    return 0;
}