| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
编译成功运行崩,菜鸟求大神指点#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <deque>
#define N 1000005
using namespace std;
int main()
{
int n, k;
scanf("%d%d", &n, &k);
int x, minx[N], maxx[N];
int j = 0;
deque <int> Q, q, M, m;
scanf("%d", &x);
Q.push_front(x);
q.push_front(x);
M.push_front(1);
m.push_front(1);
for(int i = 2; i < k; i++)
{
scanf("%d", &x);
while(x<q.back()&&!q.empty())
{
q.pop_back();
m.pop_back();
}
q.push_back(x);
m.push_back(i);
while(x>Q.back()&&!Q.empty())
{
Q.pop_back();
M.pop_back();
}
Q.push_back(x);
M.push_back(i);
}
for(int i = k; i <= n; i++)
{
scanf("%d", &x);
if(m.front()<=i-k)
{
q.pop_front();
m.pop_front();
}
if(M.front()<=i-k)
{
Q.pop_front();
M.pop_front();
}
while(x<q.back()&&!q.empty())
{
q.pop_back();
m.pop_back();
}
q.push_back(x);
m.push_back(i);
while(x>Q.back()&&!Q.empty())
{
Q.pop_back();
M.pop_back();
}
Q.push_back(x);
M.push_back(i);
minx[j] = q.front();
maxx[j] = Q.front();
j++;
}
for(int i = 0; i < j; i++)
{
printf("%d", minx[i]);
}
printf("\n");
for(int i = 0; i < j; i++)
{
printf("%d", maxx[i]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator