QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217559#4429. Gebyte's GrindVicBVicWA 2709ms151660kbC++144.4kb2023-10-16 23:40:512023-10-16 23:40:51

Judging History

你现在查看的是最新测评结果

  • [2023-10-16 23:40:51]
  • 评测
  • 测评结果:WA
  • 用时:2709ms
  • 内存:151660kb
  • [2023-10-16 23:40:51]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MV = 1ll<<(50);
const int MN = 2e6+5;
const int MQ = 4e6+5;

int n,q,h;
char tip[MN];
int val[MN];


///"desi vorbest pe inteles
///eu nu te pot pricepe." Luka, 2099
struct Luka{

    //max(Ha+b, c)
    int a,b,c;

    Luka operator *( const Luka &other)
    {
        Luka res;
        res.a=a*other.a;
        res.b=b*other.a+other.b;
        res.c=max(c*other.a+ other.b, other.c);
        assert(res.c<=MV && res.c>=-MV);
        return res;
    }

    int val(int h)
    {
        return max(h*a + b, c);
    }

    int calcLim(int otherLim)
    {
        if(c>=otherLim) return -MV;
        if(a==0) return MV;
        return (otherLim-b)/a;
    }
};

struct Arbnod{
    Luka goodFunc;
    int lim;
    Arbnod()
    {
        lim=-MV;
        goodFunc={1,0,-MV};
    }

    static Arbnod fromChar(char c, int v)
    {
        if(c=='B') return Beast(v);
        if(c=='K') return Inn(v);
        if(c=='C') return Witch(v);
        assert(0);
        return Arbnod();
    }

    static Arbnod Beast(int v)
    {
        Arbnod res;
        res.lim=v+1;
        res.goodFunc={1,-v,0};
        return res;
    }

    static Arbnod Inn(int v)
    {
        Arbnod res;
        res.lim=v;
        res.goodFunc={0,0,v};
        return res;
    }

    static Arbnod Witch(int v)
    {
        Arbnod res;
        res.lim=0;
        res.goodFunc={1,0,v};
        return res;
    }
    Arbnod operator *(const Arbnod &other)
    {
        Arbnod res;
        res.goodFunc=goodFunc*other.goodFunc;
        //cerr<<"here "<<goodFunc.a<<' '<<goodFunc.b<<' '<<goodFunc.c<<' '<<other.lim<<'\n';
        res.lim=max(lim,goodFunc.calcLim(other.lim));
        return res;
    }
};

struct Arbint{
    vector<Arbnod> arb;
    int offset;
    Arbint(int n)
    {
        offset=1;
        while(offset<n) offset<<=1;
        arb.assign(2*offset, Arbnod());
        for(int i=1;i<=n;i++)
        {
            arb[i+offset-1]=Arbnod::fromChar(tip[i],val[i]);
        }
        for(int i=offset-1;i>0;i--)
        {
            //cerr<<"calculating for "<<i<<' '<<(i<<1)<<' '<<(i<<1^1)<<"!\n";
            arb[i]=arb[i<<1]*arb[i<<1^1];
        }
    }

    void update(int poz, char c, int v)
    {
        poz+=offset-1;
        arb[poz]=Arbnod::fromChar(c,v);
        for(poz>>=1;poz>0;poz>>=1)
        {
            arb[poz]=arb[poz<<1]*arb[poz<<1^1];
        }
    }

    Arbnod culm;
    int _cb(int nod, int st, int dr,int qst)
    {
        if( dr< qst) return dr+1;
        Arbnod nextCulm=culm*arb[nod];
        if(qst<=st && nextCulm.lim<=h)
        {
            //cout<<"yo! "<<st<<' '<<dr<<' '<<nextCulm.lim<<"\n";
            culm=nextCulm;
            return dr+1;
        }

        if(st==dr)
        {
            return st;
        }

        int mid=(st+dr)/2;

        int cb_st = _cb(nod*2, st, mid, qst);
        if(cb_st==mid+1)
        {
            return _cb(nod*2+1, mid+1, dr, qst);
        }
        return cb_st;

    }

    int cb(int qst)
    {
        culm=Arbnod();
        int ans=_cb(1,1,offset, qst);
        //cout<<"here "<<ans<<' '<<culm.lim<<'\n';
        return ans-1;
    }


    void print()
    {
        int p=1;
        for(int i=1;i<2*offset;i++)
        {
            cerr<<arb[i].lim<< "( "<<arb[i].goodFunc.a<<' '<<arb[i].goodFunc.b<<' '<<arb[i].goodFunc.c<<") ";
            if(i==p)
            {
                cerr<<'\n';
                p=p<<1^1;
            }
        }
    }
};

void solve()
{
    cin>>n>>q>>h;
    for(int i=1;i<=n;i++)
    {
        cin>>tip[i]>>val[i];
    }
    Arbint arb(n);

    char qtip;
    int poz, val;
    char c;
    for(int i=1;i<=q;i++)
    {
        cin>>qtip;
        if(qtip=='Z')
        {
            cin>>poz>>c>>val;
            arb.update(poz,c,val);
        }
        else
        {
            cin>>poz;
            if(arb.arb[poz+arb.offset-1].lim>h)
            {
                cout<<-1<<'\n';
            }
            else
            {
                //cout<<"bruh\n";
                //arb.print();
                cout<<arb.cb(poz)<<'\n';
            }
        }
    }

}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2709ms
memory: 151660kb

input:

1
2000000 4000000 1000000000000
B 2982992025
B 1226542907
B 2299259203
B 1223702056
B 1407121251
B 340783317
B 1259091208
B 2101980047
B 2611543443
B 2010658889
B 4233714406
B 3112120167
B 2311876255
B 2789960428
B 3008572010
B 1
B 2464951378
B 1364240867
B 2829584762
B 2511437438
B 692948679
B 1113...

output:

833302
238155
1007466
1912727
1483707
996123
913464
595444
1956432
168794
1224759
214012
1606540
541216
578117
1279590
1652446
647870
900696
1010723
1723225
1909185
765245
1770241
994028
135066
146309
423001
379625
188229
561102
1020950
25262
1007466
624537
1150303
892424
856521
175916
1187336
16896...

result:

wrong answer 606th lines differ - expected: '2000000', found: '2097152'