QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#234888#4429. Gebyte's GrindraulandreipopWA 4081ms148172kbC++235.2kb2023-11-02 01:04:492023-11-02 01:04:49

Judging History

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

  • [2023-11-02 01:04:49]
  • 评测
  • 测评结果:WA
  • 用时:4081ms
  • 内存:148172kb
  • [2023-11-02 01:04:49]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
const int NMAX = 2e6;
const ll INF = 1e18 + 5;

struct function {
    ll a, b, y;
    ll eval (ll x)
    {
        if (x <= a) return 0;
        else if (a < x && x <= b) return y;
        else return x-b+y;
    }
    
    function o (function f2)
    {
        ll new_a , new_b , new_y;
        if (a < f2.y) {
            new_a = f2.a;
        }
        else if (a == f2.y)
        {
            new_a = f2.b;
        }
        else {
            new_a = a + f2.b - f2.y;
        }
        new_y = y;
        if (b < f2.y) {
            new_b = f2.b;
            new_y = f2.y - b + y;
        }
        else if (b == f2.y)
        {
            new_b = f2.b;
        }
        else {
            new_b = f2.y - f2.b - b;
        }
        return {new_a , new_b , new_y};
    }

    static function identity(){
        function ret;
        ret = {0,0,0};
        return ret;
    }

} initial[NMAX+10] ;

template<typename data>
struct AINT {
    vector<data> aint;
    int n, offset;
    int nextPowerOf2 (int n)
    {
        int ret = 1;
        while (ret <= n) ret *= 2;
        return ret;
    }
    AINT (int _n)
    {
        n = _n;
        offset = nextPowerOf2 (n);
        aint.resize(2*offset + 1, data::identity());
        for (int i = offset; i < 2 * offset; i++)
        {
            if (i-offset+1 <= n) {
                aint[i] = initial[i-offset+1];
            }
        }
        for (int i = offset-1; i > 0; i--)
        {
            aint[i] = merge(aint[2*i] , aint[2*i+1]);
        }
    }

    void update (int pos , data f)
    {
        upd (1 , 1 , offset , pos , f);
    }

    int CB (int pos , ll h)
    {
        int nod = pos + offset-1;
    //    cerr << offset << '\n';
    //    cerr << nod << '\n';
        data func = aint[nod];
        if (func.eval(h) == 0) return -1;
        data prev = func;
        while (func.eval(h) > 0)
        {
        //    cerr << " " << nod << ' ';
        //    cerr << func.eval(h) << '\n';
            prev = func;
            if ((nod & 1) && !(nod & (nod+1))){
                return n;
            }
            else if (nod % 2 == 1)
            {
                nod = nod/2 + 1;
                func = aint[nod].o(func);
            }
            else {
                nod /= 2;
                func = aint[nod];
                prev = data::identity();
            }
        }
        func = prev;
    //    cout << func.a << ' ' << func.b << ' ' << func.y << '\n';
    //    cerr << "  " << nod <<'\n'; 
        while (nod < offset)
        {
            data new_func = aint[2 * nod].o(func);
            if (new_func.eval(h) > 0)
            {
                func = new_func;
                nod = 2 * nod + 1;
            }
            else {
                nod = 2 * nod;
            }
        //    cerr << nod << '\n';
        }
        return nod-offset;
    }

    
    void upd (int nod , int l , int r , int pos , data f)
    {
        if (l == r)
        {
            if (l == pos) aint[nod] = f;
            return;
        }
        else if (pos < l || r < pos) return;
        int mid = (l + r) / 2;
        upd(2 * nod , l , mid , pos , f);
        upd(2*nod+1, mid+1 , r, pos , f);
        aint[nod] = merge(aint[2*nod] , aint[2*nod+1]);
        return;
    }

    data merge (data f1 , data f2)
    {
        return f2.o(f1);
    }

    void print ()
    {
        for (int nod = 1; nod < aint.size(); nod++)
        {
            cout << nod << ": " << aint[nod].a << ' ' << aint[nod].b << ' ' << aint[nod].y << '\n';
        }
    }
};

int main ()
{
    int teste; cin >> teste;
    while (teste--) {
        
        int n, q; cin >> n >> q;
        ll h; cin >> h;
        for (int i = 1; i <= n; i++)
        {
            char ch; cin >> ch;
            if (ch == 'B')
            {
                ll b; cin >> b;
                initial[i] = {b, b, 0};
            }
            else if (ch == 'K')
            {
                ll k; cin >> k;
                initial[i] = {k-1 , INF , k};
            }
            else {
                ll c; cin >> c;
                initial[i] = {0, c, c};
            }
        }
        AINT<function> aint(n);

        while (q--)
        {
        //    aint.print();
            char t; cin >> t;
        
            if (t == 'Z')
            {
                int x;
                char ch; cin >> x >>  ch;
                if (ch == 'B')
                {
                    ll b; cin >> b;
                    aint.update(x, {b, b, 0});
                }
                else if (ch == 'K')
                {
                    ll k; cin >> k;
                    aint.update(x, {k-1 , INF , k});
                }
                else {
                    ll c; cin >> c;
                    aint.update(x, {0, c, c});
                }
            }
            else {
                
                int pos; cin >> pos;
                
                cout << aint.CB(pos , h) << '\n';
            }
        }
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 4081ms
memory: 148172kb

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:

835343
241687
1021709
1919707
1494561
999055
916989
599287
1965023
249303
1227135
224255
2000000
548583
583365
1281493
1649793
653999
904823
1021753
1758105
1922341
776567
1772283
995019
151611
145023
426895
387631
250323
561073
1023427
17539
1021709
629359
1148187
889503
858471
179563
1194635
16942...

result:

wrong answer 1st lines differ - expected: '833302', found: '835343'