ABC319题解
直接从 D 开始了。
可可爱爱的二分捏。
check 就按照题目里写的就行了。
然后
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
int n,m;
int a[maxn];
int l,r = 1e18;
bool check(int x)
{
int now = a[1],cnt = 1;
for(int i = 2;i <= n;i++)
{
if(now + a[i] + 1 > x)
{
cnt++;
now = a[i];
}
else
{
now += a[i] + 1;
}
}
return cnt <= m;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
l = max(l,a[i]);
}
int ans = 0;
while(l <= r)
{
int mid = l + r >> 1;
if(check(mid))
{
r = mid - 1;
ans = mid;
}
else
{
l = mid + 1;
}
}
cout << ans;
return 0;
}
看到
由于
预处理前
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
int n,m,k,q,a[maxn],b[maxn],res[maxn];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
for(int i = 1;i < n;i++)
{
cin >> a[i] >> b[i];
}
for(int i = 0;i < 840;i++)
{
int T = i + m;
res[i] = m;
for(int j = 1;j < n;j++)
{
while(T % a[j] != 0)
{
T++;
res[i]++;
}
T += b[j];
res[i] += b[j];
}
res[i] += k;
}
cin >> q;
while(q--)
{
int x;
cin >> x;
cout << x + res[x % 840] << '\n';
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话