社区讨论

蒟蒻暴力全WA,悬关求调

P11217【MX-S4-T1】「yyOI R2」youyou 的垃圾桶参与者 10已保存回复 12

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
12 条
当前快照
1 份
快照标识符
@m2j045gy
此快照首次捕获于
2024/10/21 20:37
去年
此快照最后确认于
2025/11/04 23:49
4 个月前
查看原帖
两版赛时暴力代码全WA,一头雾水,悬关求调
CPP
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,q,w,arr[100100],l,r,d,ans,st,cnt;
void out(ll x)
{
    if(x<0)putchar('-'),x=-x;
    if(x<10)putchar(x+'0');
    else out(x/10),putchar(x%10+'0');
}
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9')
		x=x*10+ch-'0',ch=getchar();
	return x*f;
}
ll qpow(ll base,ll power)
{
    ll result=1;
    while(power>0)
    {
        if(power%2==1)
        {
            result=result*base;
        }
        base=base*base;
        power>>=1;
    }
    return result;
}
int main()
{  
    ios::sync_with_stdio(false);
    cout.tie(0);
    n=read();q=read();w=read();
    for(int i=1;i<=n;i++)
        arr[i]=read();
    for(int i=1;i<=q;i++)
    {   
        ans=0;st=w;cnt=0;
		bool op=false;
        l=read();r=read();d=read();
        for(int j=l;j<=r;j++)
        {
            arr[j]+=d;
        }
        while(st>0&&(!op))
        {
            for(int j=1;j<=n;j++)
            {
                if(st-(arr[j]*qpow((ll)2,cnt))>0)
                {
                    st-=arr[j]*qpow((ll)2,cnt);
                    ans++;
                }
                else
				{
					op=true;
					break;
				}   
                    
            }
            cnt++;
        }
        out(ans);
        printf("\n");
    }
    return 0;
}
第一版
CPP
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,q,w,arr[100100],pst[100100],mns[100100],pre[100100],l,r,d,ans,st,cnt;
void out(ll x)
{
    if(x<0)putchar('-'),x=-x;
    if(x<10)putchar(x+'0');
    else out(x/10),putchar(x%10+'0');
}
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0' && ch<='9')
		x=x*10+ch-'0',ch=getchar();
	return x*f;
}
ll qpow(ll base,ll power)
{
    ll result=1;
    while(power>0)
    {
        if(power%2==1)
        {
            result=result*base;
        }
        base=base*base;
        power>>=1;
    }
    return result;
}
int main()
{  
    ios::sync_with_stdio(false);
    cout.tie(0);
    n=read();q=read();w=read();
    for(int i=1;i<=n;i++)
    {
        arr[i]=read();
        mns[i]=arr[i]-arr[i-1];
    }
    for(int i=1;i<=q;i++)
    {   
        memset(pre,0,sizeof(pre));
        memset(pst,0,sizeof(pst));
        ans=0;st=w;cnt=0;
		bool op=false;
        l=read();r=read();d=read();
        mns[l]+=d;mns[r+1]-=d;
        for(int j=1;j<=n;j++)
        {
            pst[j]=pst[j-1]+mns[j];
            pre[j]=pre[j-1]+pst[j];
        }
        for(int j=0;;j++)
        {
            if(st>pre[n]*qpow((ll)2,j))
            {
                ans+=n;
                st-=(pre[n]*qpow((ll)2,j));
                continue;
            }
            else
            {
                auto it=lower_bound(pre+1,pre+n+1,(ceil)((double)st/(double)qpow((ll)2,j)));
                ans+=(it-1-pre);
                break;
            }
        }
        out(ans);
        printf("\n");
    }
    return 0;
}
第二版
纯粹暴力骗到20,策略性暴力(雾)一分没得,引起群嘲(喜)

回复

12 条回复,欢迎继续交流。

正在加载回复...