Cod sursa(job #2409638)

Utilizator razviii237Uzum Razvan razviii237 Data 19 aprilie 2019 12:26:33
Problema Secventa Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("secventa.in");
ofstream g("secventa.out");

struct xy { int x, y, z; };

const int maxn = 5e5+5;

xy q[maxn]; int k, p;

int n, m, i, x;
xy best;
int v[maxn];

bool operator > (xy a, xy b) { return a.x > b.x; }

int a, b, len;

void bs(int x) {
    int b = 1 << 19, r = k + 1;
    while(b > 0) {
        if(r - b >= p && q[r - b].x > x) {
            r -= b;
        }
        b >>= 1;
    }
    k = r - 1;
}

int main()
{
    best = {-0x3f3f3f3f, 0, 0};
    f >> n >> m;
    for(i = 1; i <= n; i ++) {
        f >> x; v[i] = x;
        if(p == 0 || q[p].y == i - m) { ++ p; }

        /*while(k >= p && x < q[k].x) {
            -- k;
        }*/
        bs(x);

        int val3 = q[k].y + 1;
        if(k < p) {
            val3 = i - m + 1;
            if(val3 < 1) {
                val3 = 1;
            }
        }
        q[++k] = {x, i, val3};
        if(q[p] > best && i >= m) { best = q[p]; }
    }
    g << best.z << ' ' << best.z + m - 1 << ' ' << best.x << '\n';

    f.close(); g.close();
    return 0;
}