丶雖 @ 2019-08-28 20:25:17
using namespace std;
int n, k, a[1000005];
deque<int>q;
deque<int>p;
deque<int>q1;
deque<int>p1;
int minz()
{
for(int i = 1; i <= n; i++)
{
while(a[i] < q1.back() && !q1.empty())
{
q1.pop_back();
p1.pop_back();
}
q1.push_back(a[i]);
p1.push_back(i);
while(p1.front() <= i - k && !q1.empty())
{
p1.pop_front();
q1.pop_front();
}
if(i >= k)
printf("%d ", q1.front());
}
printf("\n");
}
int maxz()
{
for(int i = 1; i <= n; i++)
{
while(a[i] > q.back() && !q.empty())
{
q.pop_back();
p.pop_back();
}
q.push_back(a[i]);
p.push_back(i);
while(p.front() <= i - k && !q.empty())
{
p.pop_front();
q.pop_front();
}
if(i >= k)
printf("%d ", q.front());
}
printf("\n");
}
int main()
{
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
minz();
maxz();
return 0; }
by 吾皇 @ 2019-08-28 20:26:06
使Md
by xuyiyan920 @ 2019-08-28 20:27:56
希望更丰富的展现?使用Markdown
by 徐赫铖 @ 2019-08-28 20:31:45
include<bits/stdc++.h>
using namespace std;
int n, k, a[1000005];
deque<int>q;
deque<int>p;
deque<int>q1;
deque<int>p1;
int minz()
{
for(int i = 1; i <= n; i++)
{
while(a[i] < q1.back() && !q1.empty())
{
q1.pop_back();
p1.pop_back();
}
q1.push_back(a[i]);
p1.push_back(i);
while(p1.front() <= i - k && !q1.empty())
{
p1.pop_front();
q1.pop_front();
}
if(i >= k)
printf("%d ", q1.front());
}
printf("\n");
}
int maxz()
{
for(int i = 1; i <= n; i++)
{
while(a[i] > q.back() && !q.empty())
{
q.pop_back();
p.pop_back();
}
q.push_back(a[i]);
p.push_back(i);
while(p.front() <= i - k && !q.empty())
{
p.pop_front();
q.pop_front();
}
if(i >= k)
printf("%d ", q.front());
}
printf("\n");
}
int main()
{
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
minz();
maxz();
return 0; }
格式好一点
by 只以 @ 2019-08-28 20:31:45
红名dalao居然不会用MD!?
by 徐赫铖 @ 2019-08-28 20:32:06
cin 输入
by EtOH_Lewis @ 2019-08-28 20:40:26
@只以 谁说红名就是大佬了,我有一次切了2道水紫,瞬间红名,持续20天左右掉了
by 只以 @ 2019-08-28 20:42:09
@奥特曼曹特尔 您为何如此刁钻?
by Aehnuwx @ 2019-08-28 20:58:18
Orz
by EtOH_Lewis @ 2019-08-29 18:41:12
@只以 越是高科技的东西就越得精细化。比如辽宁号上掉了一个螺丝钉,很有可能整个船就沉没了