码风过丑怎么办
  • 板块灌水区
  • 楼主DengDuck鄧德
  • 当前回复24
  • 已保存回复24
  • 发布时间2022/6/1 21:20
  • 上次更新2023/10/28 00:07:38
查看原帖
码风过丑怎么办
501947
DengDuck鄧德楼主2022/6/1 21:20
void exgcd1(ll a,ll b,ll &d,ll &x,ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        d=a;
        return;
    }
    exgcd1(b, a % b,d,y,x);
    y -= a / b * x;
    return;
}
ll exgcd(ll a,ll b,ll c)
{
    ll d,x,y;
    exgcd1(a,b,d,x,y);
    if(c%d!=0)
    {
        return -1;
    }
    else
    {
        return ( (x*c/d)%(b/d)+(b/d))%(b/d);
    }
}

#include<bits/stdc++.h>
using namespace std;
unsigned long long n,op,x,y,sum;
struct node
{
    unsigned long long a,b;
}a[2000007];
unsigned long long h=1,t,k;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>op>>x;
        if(op==1)
        {
            cin>>y;
            a[++t].a=x;
            a[t].b=y;
        }
        else
        {
            sum=0;
            k=x;
            while(k>=a[h].b&&h>=t)
            {
                k-=a[h].b;
                sum+=a[h].b*a[h].a;
                a[n].b=0;
                h++;
            }
            sum+=k*a[h].a;
            a[h].b-=k;                
            cout<<sum<<endl;
        }
    }
}
2022/6/1 21:20
加载中...