王诗琪 @ 2019-10-27 15:53:26
如题,蒟蒻实在调不出来了……
WA了第一个点,-94读进来成了94(然而DEV这个数据过的去是正常的,洛谷在线IDE不行,测评也不行)
(换成cin就满分了,所以肯定是快读的问题,嘤)
求大佬康康!!!谢谢您!!!祝您RP++!
(数据在代码下面)
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,k,a[1000001],q[1000001],p[1000001],head,tail;
inline int read()
{
int x=0;
char c=getchar();
int flag=1;
while (c=='-') flag*=-1,c=getchar();
while (c>'9'||c<'0') c=getchar();
while (c<='9'&&c>='0') x=x*10+c-48,c=getchar();
x*=flag;
return x;
}
int main()
{
n=read(); k=read();
for (int i=1; i<=n; i++)
a[i]=read();
// min
head=1,tail=0;
for (int i=1; i<=n; i++)
{
while (head<=tail&&q[tail]>=a[i])//
tail--;
q[++tail]=a[i];
p[tail]=i;
while (p[head]<=i-k) head++;//!!
if (i>=k) cout<<q[head]<<" ";
}
cout<<endl;
head=1,tail=0;
for (int i=1; i<=n; i++)
{
while (head<=tail&&q[tail]<=a[i])//
tail--;
q[++tail]=a[i];
p[tail]=i;
while (p[head]<=i-k) head++;//!!
if (i>=k) cout<<q[head]<<" ";
}
return 0;
}
/*
input
10 3 -94 21 24 73 38 77 11 73 9 -88
output
-94 21 24 38 11 11 9 -88 24 73 73 77 77 77 73 73
*/
by XyzL @ 2019-10-27 15:56:57
while (c=='-') flag*=-1,c=getchar();
while (c>'9'||c<'0') c=getchar();
@王诗琪 您看,这句错了 应该是这样:
while (c>'9'||c<'0')
{
if(c == ‘-’)
{
flag*=-1;
}
c=getchar();
}
by wyhwyh @ 2019-10-27 15:57:06
while(c=='-')
?
by XyzL @ 2019-10-27 15:57:17
快读要多打!
by wyhwyh @ 2019-10-27 15:57:56
啊,发晚了一步x
by XyzL @ 2019-10-27 15:58:03
莫名想起某次模拟赛调了1个小时的,最后是快读(fread)的锅
by XyzL @ 2019-10-27 15:58:42
@wyhwyh 没事啊,有善心就好了,别人会看见的,兮兮(#^.^#)
by 王诗琪 @ 2019-10-27 16:00:58
@XyzL 啊啊,明白了!!!谢谢您!!!
会再去多打几遍的!谢谢!!!!
by 王诗琪 @ 2019-10-27 16:01:29
@wyhwyh 谢谢您!!!!!!!
by XyzL @ 2019-10-27 16:02:06
@王诗琪 !!! !!!! !!!! !! !
by wyhwyh @ 2019-10-27 16:08:31
您们都不屑于打月赛的吗qwq