社区讨论
站外题求调
学术版参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mi8t2rte
- 此快照首次捕获于
- 2025/11/21 19:57 3 个月前
- 此快照最后确认于
- 2025/11/21 20:51 3 个月前

TLE but not WA
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define AQEW tie
#define nc() (pasjk==pdsfhs && (pdsfhs=(pasjk=dsfsfadgfjhkl)+fread(dsfsfadgfjhkl,1,100000,stdin),pasjk==pdsfhs)?EOF:*pasjk++)
using namespace std;
char *pasjk,*pdsfhs,dsfsfadgfjhkl[100000];
int read(){
int x=0,f=1;
char ch=nc();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=nc();
}
while(ch>='0'&&ch<='9')
x=x*10+ch-'0',ch=nc();
return x*f;
}
const int N=3e5+10;
int da[N],hp[N];
vector<int> g[N];
signed main(){
// freopen("h.in","r",stdin);
// freopen("h.out","w",stdout);
ios::sync_with_stdio(0);
cin.AQEW(0);
cout.AQEW(0);
int n=read(),m=read(),V=read();
for(int i=1;i<=n;i++){
da[i]=read();
hp[i]=read();
hp[i]--;
for(int l=1;l<=hp[i];){
int r=hp[i]/(hp[i]/l);
g[l].push_back(i);
l=r+1;
}
g[hp[i]+1].push_back(i);
}
int DA=read(),HP=read();
int zz=DA+1,ans,mxhp=HP;
for(int j=1;j<=n;j++){
int cs=hp[j]/DA+1;
HP-=cs*da[j];
if(HP<=0){
mxhp-=HP;
ans=j;
cout<<j<<" \n";
break;
}
if(j==n){
ans=-1;
cout<<"-1 \n";
}
}
// cout<<mxhp;
for(int i=2;i<=m;i++){
DA=read();
HP=read();
if(ans>n){
cout<<-1<<" \n";
continue;
}
for(int j=zz;j<=DA;j++){
for(int xx:g[j]){
if(xx<=ans){
mxhp-=da[xx]*(hp[xx]/(j-1)-hp[xx]/j);
}
}
}
// cout<<mxhp<<" ";
if(mxhp<HP){
// cout<<i;
ans++;
for(;ans<=n;ans++){
mxhp+=(hp[ans]/DA+1)*da[ans];
if(mxhp>=HP){
break;
}
}
}
if(ans>n){
cout<<-1<<" \n";
}
else{
cout<<ans<<" \n";
}
zz=DA+1;
}
return 0;
}
CPP正解but WA
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define AQEW tie
#define nc() (pasjk==pdsfhs && (pdsfhs=(pasjk=dsfsfadgfjhkl)+fread(dsfsfadgfjhkl,1,100000,stdin),pasjk==pdsfhs)?EOF:*pasjk++)
using namespace std;
char *pasjk,*pdsfhs,dsfsfadgfjhkl[100000];
int read(){
int x=0,f=1;
char ch=nc();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=nc();
}
while(ch>='0'&&ch<='9')
x=x*10+ch-'0',ch=nc();
return x*f;
}
const int N=3e5+10;
int da[N],hp[N];
int f[N];
signed main(){
// freopen("h.in","r",stdin);
// freopen("h.out","w",stdout);
ios::sync_with_stdio(0);
cin.AQEW(0);
cout.AQEW(0);
int n=read(),m=read(),V=read();
for(int i=1;i<=n;i++){
da[i]=read();
hp[i]=read();
hp[i]--;
}
int zz=1,ans=0;
for(int i=1;i<=m;i++){
int DA,HP;
DA=read();
HP=read();
if(ans>n){
cout<<-1<<"\n";
continue;
}
for(int j=zz;j<=DA;j++){
f[j]+=f[j-1];
}
if(f[DA]<HP){
ans++;
for(;ans<=n;ans++){
int l=DA;
for(;l<=hp[ans];){
int r=hp[ans]/(hp[ans]/l);
f[l]+=(hp[ans]/l+1)*da[ans];
if(r+1<=hp[ans]){
f[r+1]-=(hp[ans]/l+1)*da[ans];
}
l=r+1;
}
f[hp[ans]+1]+=da[ans];
if(f[DA]>=HP){
break;
}
}
}
if(ans>n){
cout<<-1<<"\n";
}
else{
cout<<ans<<"\n";
}
zz=DA+1;
}
return 0;
}
都是整除分块
回复
共 3 条回复,欢迎继续交流。
正在加载回复...