洛谷 P8572 [JRKSJ R6] Eltaw 做题记录
zhr 随机跳题跳到的,遂做之。
注意到
当
当
取阀值为
点击查看代码
int n,k,q;
vector<int>a[maxn];
vector<int>pre[maxn];
const int lim=750;
int ans[lim+5][lim+5];
signed main() {
in3(n,k,q);
For(i,1,k) {
a[i].push_back(0);
pre[i].push_back(0);
For(j,1,n) {
int x;
in1(x);
a[i].push_back(x);
pre[i].push_back(x+pre[i][j-1]) ;
}
}
if(k<lim) {
For(i,1,q) {
int l,r;
in2(l,r);
int ans=-1e18;
For(j,1,k)
ans=max(ans,pre[j][r]-pre[j][l-1]);
cout<<ans<<'\n';
}
return 0;
}
For(i,1,n) For(j,1,n) ans[i][j]=-1e18;
For(i,1,k) {
For(j,1,n) {
int tot=0;
For(p,j,n) {
tot+=a[i][p];
ans[j][p]=max(ans[j][p],tot);
}
}
}
For(i,1,q) {
int l,r;
in2(l,r);
cout<<ans[l][r]<<'\n';
}
}
本文来自博客园,作者:coding_goat_qwq,转载请注明原文链接:https://www.cnblogs.com/CodingGoat/p/18472376
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步