2017.10.14 T1 1980
样例数据
输入
5 5
1 2 3 5 6
1
2
3
4
5
输出
4
4
4
4
7
分析:前几天才学习(其实是复习)了一下ST表,今天就想着用ST表解决去了orz,然后我发现杀鸡焉用牛刀欸,从大到小一个DP就出来了,也许,这就是Liu Chenrui神犇建议我们考试前不要打板的原因了吧……
但是,我竟然WA了两个点!!!数据出锅了?我想,怎么能WA两个点???结果,我发现是我边界写错了,现在我是庆幸居然只WA了两个点哈哈哈。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
#include<set>
using namespace std;
int getint()
{
int sum=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
if(ch=='-')
{
f=-1;
ch=getchar();
}
for(;isdigit(ch);ch=getchar())
sum=(sum<<3)+(sum<<1)+ch-48;
return sum*f;
}
const int maxn=200010;
int n,m,t,q,maxt;
int ans[maxn];
bool bj[maxn];
int main()
{
freopen("machine.in","r",stdin);
freopen("machine.out","w",stdout);
n=getint(),m=getint();
for(int i=1;i<=n;++i)
{
t=getint(),bj[t]=1;
maxt=max(maxt,t);
}
for(int i=200001;i>=1;--i)//边界是200001不是200000,200001需要被更新,因为当机器在200000时工作,需要的ans是200001而不是0(边界判错的话就是ans[200000]=ans[200000+1]=0)
{
if(i>maxt)//我也不知道我为什么还要判一个i>maxt,也许考试的时候脑子抽了觉得这样快一点吧
ans[i]=i;
else if(!bj[i])
ans[i]=i;
else
ans[i]=ans[i+1];
}
for(int i=1;i<=m;++i)
{
q=getint();
cout<<ans[q]<<'\n';
}
return 0;
}
本题结。