社区讨论
TLE+RE,求调
P8249模法问题参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mlhhkgqx
- 此快照首次捕获于
- 2026/02/11 11:44 上周
- 此快照最后确认于
- 2026/02/11 11:55 上周
CPP
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a,b;
int cnt;
int q,l,r;
int st[N][50];
int ans;
signed main(){
cin>>a>>b;
cin>>q;
for(int i=1;i<=a*b;i++){
int u=i%a,v=i%b;
st[i][0]=u+v;
ans=max(ans,st[i][0]);
}
for(int j=1;(1<<j)<=a*b;j++){
for(int i=1;i<=a*b-(1<<j)+1;i++){
st[i][j]=max(st[i][j-1],st[i+(1<<j-1)][j-1]);
}
}
while(q--){
cin>>l>>r;
cnt=0;
if(r-l>=a*b) cout<<ans<<"\n";
else{
while((1<<(cnt+1))<=r-l) cnt++;
cout<<max(st[l][cnt],st[r-(1<<cnt)+1][cnt])<<"\n";
}
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...