QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#929255#9727. Barkley IIIhshhhWA 0ms3584kbC++204.3kb2025-03-08 19:07:222025-03-08 19:07:27

Judging History

This is the latest submission verdict.

  • [2025-03-08 19:07:27]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-03-08 19:07:22]
  • Submitted

answer

#include <bits/stdc++.h>
#include <climits>
using namespace std;
using i64 = unsigned long long;
const int INF = 0x3f3f3f3f;
const i64 mod = 1e9 + 7;
const int N = 200005;
const i64 mask = (1ULL<<63)-1;
//线段树维护区间与
//同时需要维护区间那些为只出现了一次为0
//然后删除这个数
i64 a[N];
struct SegementTree {
    #define lson ((cur<<1))
    #define rson ((cur<<1)|1)
    #define mid ((l+r)>>1)

    vector<i64> d, f;
    vector<bool> lazy;

    void pushup(int cur) {
        d[cur] = d[lson]&d[rson];

        f[cur] = (f[lson]&d[rson]) | (f[rson]&d[lson]);
    }
    void pushdown(int cur, int l, int r) {
        d[lson] = d[rson] = d[cur];

        f[lson] = (mid == l ? mask^(d[cur]) : 0);
        f[rson] = (mid+1 == r ? mask^(d[cur]) : 0);
        lazy[cur] = 0;
        lazy[lson] = lazy[rson] = 1; 
    }
    void update(int cur, int l, int r, int L, int R, int v) {
        if(L <= l and r <= R) {
            d[cur] = v;
            f[cur] = (l == r ? mask^(v) : 0);
            lazy[cur] = 1;
            return;
        }
        if(lazy[cur]) {
            pushdown(cur, l, r);
        }

        if(L <= mid) {
            update(lson, l, mid, L, R, v);
        }
        if(R > mid) {
            update(rson, mid+1, r, L, R, v);
        }
        pushup(cur);
    }

    pair<i64, i64> query(int cur, int l, int r, int L, int R) {
        if(L <= l and r <= R) {
            return  {d[cur], f[cur]};
        }
        if(lazy[cur]) {
            pushdown(cur, l, r);
        }
        i64 td, tf;
        if(L <= mid and R > mid) {  
            auto r1 = query(lson, l, mid, L, R);
            auto r2 = query(rson, mid+1, r, L, R);
            td = r1.first&r2.first;
            tf = (r1.first&r2.second) | (r1.second&r2.first);
            return {td, tf}; 
        }
        else if(L <= mid) {
            return query(lson, l, mid, L, R);
        }
        else {
            return query(rson, mid+1, r, L, R);
        }
    }
    i64 find(int cur, int l, int r, int L, int R, i64 target) {
        if(lazy[cur]) {
            pushdown(cur, l, r);
        }
        if(L <= l and r <= R) {
            if(f[cur]&target) {
                if(l == r) {
                    return f[cur];
                }
                if(f[lson]&target) {
                    return find(lson, l, mid, L, R, target);
                }
                else {
                    return find(rson, mid+1, r, L, R, target);
                }
            }
            else {
                return 0;
            }
        }
        else {
            i64 ret = 0;
            if(L <= mid) {
                ret = max(ret, find(lson, l, mid, L, R, target));
            }
            if(R > mid and !ret) {
                ret = max(ret, find(rson, mid+1, r, L, R, target));
            }
            return ret;
        }
    }
    void buildTree(int cur, int l, int r) {
        if(l == r) {
            d[cur] = a[l];
            f[cur] = (mask^d[cur]);
            return;
        }
        buildTree(lson, l, mid);
        buildTree(rson, mid+1, r);
        pushup(cur);
    }
    SegementTree(int n) : d(n<<2, 0), f(n<<2, 0), lazy(n<<2, 0) {
        buildTree(1, 1, n);
    }
};
void solve() {
    i64 n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    SegementTree T(n);
    while(k--) {
        i64 opt, l, r, x;
        cin >> opt;
        if(opt == 1) {
            cin >> l >> r >> x;
            T.update(1, 1, n, l, r, x);
        }
        else if(opt == 2) {
            cin >> l >> x;
            T.update(1, 1, n, l, l, x);
        }
        else {
            cin >> l >> r;
            auto [d, f] = T.query(1, 1, n, l, r);
            if(f) {
                for(i64 t = 1LL<<63; t > 0; t >>= 1) {
                    if(t&f) {
                        i64 tmp = T.find(1, 1, n, l, r, t);
                        d = d + (f&tmp);
                        break;
                    }
                }
            }
            cout << d << '\n';
        }

    }
};
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
    // cout << ((1LL<<63)-1) << '\n';
    // cout << (((1LL<<63)-1)^(1LL<<62));

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

5 9
7 7 7 6 7
3 1 5
2 1 3
3 1 5
3 1 3
1 1 2 3
3 1 3
2 2 8
3 1 3
3 1 2

output:

7
6
7
3
3
8

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3584kb

input:

10 10
6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482
1 3 5 7587422031989082829
3 6 10
1 7 8 5197616143400216932
2 4 2518604563805514908
2 2 4533959...

output:

1568091718842717482
570427392
537919776
9223372036769847400

result:

wrong answer 2nd lines differ - expected: '35184908959744', found: '570427392'