Pagini recente » Cod sursa (job #405326) | Cod sursa (job #2558415) | Cod sursa (job #33605) | Cod sursa (job #2616911) | Cod sursa (job #2409661)
#include <iostream>
#include <fstream>
#include <cstdio>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
InParser 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;
}