比赛 |
EYOI暨SBOI暑假快乐赛3rd |
评测结果 |
WWWWWWWWWWWWWWWWTTTT |
题目名称 |
最小环(民间数据) |
最终得分 |
0 |
用户昵称 |
ZRQ |
运行时间 |
22.484 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2022-06-27 11:40:48 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=200010;
int n,m,a[N],k[N];
char ch;
ll ans[N];
inline void read(int &x)
{
x=0,ch=getchar();
while(ch<48||ch>57) ch=getchar();
while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
}
ll calc(int k)
{
ll res=0;
for(int i=1;i<=n;++i)
{
int nt=i+k;
if(nt>n) nt-=n;
res+=a[i]*a[nt];
}
return res;
}
int random(int n)
{
return (unsigned)rand()*rand()%n+1;
}
void SA(int i)
{
ll res=0;
random_shuffle(a+1,a+n+1);
for(double t=1e8;t>=1e-8;t*=0.99)
{
ll x=calc(k[i]);
res=max(x,res);
ll n1=random(n),n2=n1%n+1;
swap(n1,n2);
ll y=calc(k[i]);
res=max(y,res);
if(exp(-(y-x)/t)<(double)rand()/RAND_MAX) swap(n1,n2);
}
ans[i]=max(ans[i],res);
return ;
}
void solve()
{
for(int i=1;i<=m;++i)
{
if((double)clock()/CLOCKS_PER_SEC>0.96) break;
if(k[i]) SA(i);
}
return ;
}
int main()
{
freopen("noi_online2020_ring.in","r",stdin);
freopen("noi_online2020_ring.out","w",stdout);
srand((unsigned)time(0));
read(n),read(m);
for(int i=1;i<=n;++i) read(a[i]);
for(int i=1;i<=m;++i) read(k[i]);
for(int i=1;i<=m;++i)
if(!k[i])
for(int j=1;j<=n;++j)
ans[i]+=a[j]*a[j];
while((double)clock()/CLOCKS_PER_SEC<0.95) solve();
for(int i=1;i<=m;++i) printf("%lld\n",ans[i]);
return 0;
}