Use C++ instead of G++

From http://blog.csdn.net/alongela/article/details/8229659
This commit is contained in:
Kirigaya Kazuto 2016-09-10 11:51:02 +08:00 committed by GitHub
parent 16b72a6281
commit ed8377f94d

79
POJ/2823_alongela.cpp Normal file
View File

@ -0,0 +1,79 @@
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1000005;
struct Elem
{
int val;
int pos;
};
Elem maxque[N];
Elem minque[N];
int maxhead, minhead, maxtail, mintail;
int maxans[N];
int minans[N];
int cur;
int main()
{
int n, w, num;
scanf("%d%d", &n, &w);
minhead = mintail = 0;
maxhead = maxtail = 0;
cur = 0;
for (int i = 0; i < w; ++i)
{
scanf("%d", &num);
while (minhead < mintail && minque[mintail - 1].val >= num) --mintail;
minque[mintail].val = num;
minque[mintail].pos = i;
++mintail;
while (maxhead < maxtail && maxque[maxtail - 1].val <= num) --maxtail;
maxque[maxtail].val = num;
maxque[maxtail].pos = i;
++maxtail;
}
for (int i = w; i < n; ++i)
{
minans[cur] = minque[minhead].val;
maxans[cur] = maxque[maxhead].val;
++cur;
scanf("%d", &num);
while (minhead < mintail && i - minque[minhead].pos >= w) ++minhead;
while (minhead < mintail && minque[mintail - 1].val >= num) --mintail;
minque[mintail].val = num;
minque[mintail].pos = i;
++mintail;
while (maxhead < maxtail && i - maxque[maxhead].pos >= w) ++maxhead;
while (maxhead < maxtail && maxque[maxtail - 1].val <= num) --maxtail;
maxque[maxtail].val = num;
maxque[maxtail].pos = i;
++maxtail;
}
minans[cur] = minque[minhead].val;
maxans[cur] = maxque[maxhead].val;
++cur;
for (int i = 0; i < cur; ++i)
{
if (i > 0) putchar(' ');
printf("%d", minans[i]);
}
printf("\n");
for (int i = 0; i < cur; ++i)
{
if (i > 0) putchar(' ');
printf("%d", maxans[i]);
}
printf("\n");
return 0;
}