137QWQ @ 2022-07-31 10:31:25
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const int M=2147483647;
int main()
{
int n,m,a[N],qlog[N];
int t=1,q=-1;
cin>>n>>m;
for(int i=1;i<=n;i++) //快速log
{
if(t==i)
t*=2,++q;
qlog[i]=q;
//cout<<qlog[i]<<" ";
}
//cout<<endl;
int b[N][qlog[N]];
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i][0]=a[i];
cout<<b[i][0]<<" "; //输出1
}
cout<<endl;
for(int i=1;i<=n;i++)
cout<<b[i][0]<<" "; //输出2
}
输入: 8 3 1 3 -1 -3 5 3 6 7
输出(本代码):
1 3 -1 -3 5 3 6 7
7 7 7 7 7 7 7 7
by ande @ 2022-07-31 10:36:20
int b[N][qlog[N]];
??
by 137QWQ @ 2022-07-31 10:41:26
QWQ
by irris @ 2022-07-31 10:42:30
你写的都是什么寂寞
by 137QWQ @ 2022-07-31 10:43:16
@ande
好吧 找到问题了
for(int i=1;i<=n;i++) n改为N
谢谢
by 137QWQ @ 2022-07-31 10:43:40
QWQ
by 137QWQ @ 2022-07-31 10:59:20
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const int M=2147483647;
int main()
{
int n,m,a[N],qlog[N];
int t=1,q=-1;
cin>>n>>m;
for(int i=1;i<=N;i++) //快速log
{
if(t==i)
t*=2,++q;
qlog[i]=q;
//cout<<qlog[i]<<" ";
}
//cout<<endl;
int b[N][qlog[N]+1],c[N][qlog[N]+1];
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i][0]=a[i];
}
for(int j=1;j<=qlog[n];j++)
{
for(int i=1;i<=n;i++)
{
b[i][j]=max(b[i][j-1],b[i+(1<<(j-1))][j-1]);
c[i][j]=min(b[i][j-1],b[i+(1<<(j-1))][j-1]);
}
}
for(int i=1;i<=n-m+1;i++)
{
int k=qlog[m];
cout<<min(c[i][k],c[i+m-(1<<k)][k])<<" ";
}
cout<<endl;
for(int i=1;i<=n-m+1;i++)
{
int k=qlog[m];
cout<<max(b[i][k],b[i+m-(1<<k)][k])<<" ";
}
}
https://www.luogu.com.cn/record/81884482
MLE #2 #9 #10 WA #3 #4 #5 #6 #7 #8
求助 这代码还有救吗……