QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1523#885022#9737. Let's Go! New AdventurecooluoXY_ElevenFailed.2025-02-06 16:56:232025-02-06 16:56:23

Details

Extra Test:

Invalid Input

input:

1
16 20 131208411957
664689936118 666449345281 268138443177 205845719806 521120192342 434357635903 74929313847 524196771766 937500062275 549654175523 659151679873 876225951837 760817863290 719043788712 629149837311 758193211565
46727039756 78699012160 99997882259 108966050954 186730364672 2099163090...

output:


result:

FAIL Expected int32, but "131208411957" found (test case 1, stdin, line 2)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#885022#9737. Let's Go! New AdventureXY_ElevenAC ✓1181ms15668kbC++235.9kb2025-02-06 12:59:392025-02-06 12:59:46

answer

#include <bits/stdc++.h>
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<long long,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }

void main_init()
{

}
const DB inf=1e18;
cint N=5.01e5;
int n,m;
LL cost,a[N],b[N];
LL dp[N];
int fun(LL w)
{
    int l=0,r=m+1,mid;
    while(l+1<r)
        (b[mid=l+r>>1]<=w?l:r)=mid;
    // printf("%lld:%d\n",w,l);
    return l;
}
DB fun2(LL w)
{
    int l=0,r=m+1,mid;
    while(l+1<r)
        (b[mid=l+r>>1]<=w?l:r)=mid;
    return ((DB)l+(l==m?((DB)0.0):((DB)(w-b[l])/(b[l+1]-b[l]))));
}
deque <array<int,2> > st;
DB to(int j,int i)
{
    return ((DB)dp[j]+fun2(a[i]-a[j]));
}
void main_solve()
{
    inpr(n,m); inll(cost);
    For(i,1,n) inll(a[i]),a[i]+=a[i-1];
    For(i,1,m) inll(b[i]),b[i]+=b[i-1];
    // printf("%lf\n",to(0,1));
    // printf("%lf\n",to(0,2));
    // printf("%lf\n",to(0,3));
    // printf("%lf\n",to(0,4));
    while(!st.empty()) st.pop_back();
    st.push_back({n,0});
    For(i,1,n)
    {
        assert(!st.empty());
        // printf("i=%d\n",i);
        // printf("%d->%d\n",st.front()[1],i);
        dp[i]=dp[st.front()[1]]+fun(a[i]-a[st.front()[1]])-cost;
        if(st.front()[0]==i) st.pop_front();
        int len=sz(st); bool ck=false;
        // printf("> len=%d\n",len);
        while(!st.empty())
        {
            // printf("len=%d\n",len);
            int l=(len==1?i:st[len-2][0])+1;
            // printf("l=%d\n",l);
            // printf("%d->%d:%lf\n",st.back()[1],l,to(st.back()[1],l));
            // printf("%d->%d:%lf\n",i,l,to(i,l));
            if(to(st.back()[1],l)<to(i,l))
            {
                ck=true;
                st.pop_back();
                len--;
                // printf("%d->%d\n",len+1,len);
                continue;
            }
            int r=st.back()[0]+1,mid;
            while(l+1<r)
            {
                mid=l+r>>1;
                (to(st.back()[1],mid)<to(i,mid)?r:l)=mid;
            }
            if(r<=st.back()[0])
            {
                st.back()[0]=r-1;
                st.push_back({n,i});
            }
            else if(ck)
                st.push_back({n,i});
            ck=false;
            break;
        }
        if(ck)
            st.push_back({n,i});
    }
    // For(i,1,n) outll_(dp[i]);
    outll(dp[n]);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("ex_block4.in","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    // cerr<<clock()<<'\n';
    return 0;
}
/*
2
5 4 2
1 0 3 1 2
0 1 1 2
4 5 1
7 16 23 4
1 3 6 20 20

*/