QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743131#9727. Barkley IIILegend_dy#WA 1ms5664kbC++204.0kb2024-11-13 18:20:592024-11-13 18:21:00

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-13 18:21:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5664kb
  • [2024-11-13 18:20:59]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define ls (w << 1)
#define rs (w << 1 | 1)

using namespace std;
using ull = unsigned long long;

const int N = 1e6 + 5;
const ull MAX = (1ull << 63) - 1;
struct Node {
    int l, r;
    ull tag;
    ull A, B;
} tr[N << 2];
ull a[N];

inline void pushUp(int w) {
    tr[w].A = (tr[ls].A & tr[rs].A);
    tr[w].B = ((tr[ls].A & tr[rs].B) | (tr[ls].B & tr[rs].A));
}

inline void apply(int w, ull x, int l, int r) {
    if (l == r) {
        tr[w].A &= x;
        tr[w].B = (~tr[w].A);
    }else {
        tr[w].A &= x;
        tr[w].B &= x;
    }
    tr[w].tag &= x;
}

inline void pushDown(int w) {
    if (tr[w].tag != MAX) {
        apply(ls, tr[w].tag, tr[ls].l, tr[ls].r);
        apply(rs, tr[w].tag, tr[rs].l, tr[rs].r);
        tr[w].tag = MAX;
    }
}

void build(int w, int l, int r) {
    tr[w].l = l; tr[w].r = r;
    tr[w].tag = MAX;
    if(l == r) {
        tr[w].A = a[l];
        tr[w].B = (~a[l]) & MAX;
        return;
    }
    int mid = (l + r) >> 1;
    build(ls, l, mid);
    build(rs, mid + 1, r);
    pushUp(w);
}

void modify(int w, int ql, int qr, ull x) {
    if (ql <= tr[w].l && tr[w].r <= qr) {
        apply(w, x, tr[w].l, tr[w].r);
        return;
    }
    pushDown(w);
    int mid = tr[ls].r;
    if (qr > mid) modify(rs, ql, qr, x);
    if (ql <= mid) modify(ls, ql, qr, x);
    pushUp(w);
}

void modify(int w, int s, ull x) {
    if (tr[w].l == tr[w].r) {
        tr[w].A = x;
        tr[w].B = (~x) & MAX;
        return;
    }
    pushDown(w);
    int mid = tr[ls].r;
    if (s <= mid) modify(ls, s, x);
    else modify(rs, s, x);
    pushUp(w);
}

pair<ull, ull> ask(int w, int ql, int qr) {
    if (ql <= tr[w].l && tr[w].r <= qr) {
        return {tr[w].A, tr[w].B};
    }
    int mid = tr[ls].r;
    if(tr[ls].r >= ql) {
        pair<ull, ull> pll = ask(ls, ql, qr), pll2;
        if(tr[rs].l <= qr) {
            pll2 = ask(rs, ql, qr);
            return {pll.first & pll2.first, 
                    (pll.first & pll2.second) | (pll2.first & pll.second)};
        }
        return pll;
    } else {
        return ask(rs, ql, qr);
    }
}
int Find(int w, int ql, int qr, int p) {
    if (tr[w].r < ql || tr[w].l > qr || (tr[w].A >> p & 1)) return -1;
    if (tr[w].l == tr[w].r) return tr[w].l;
    pushDown(w);
    int mid = tr[ls].r;
    int res = Find(ls, ql, qr, p);
    if (res == -1) {
        res = Find(rs, ql, qr, p);
    }
    return res;
}
inline ull HighBit(ull x) {
    for (int i = 63; i >= 0; i--) {
        if (x >> i & 1) return i;
    }
    return -1;
}

void solve() {
    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    build(1, 1, n);
    while(q--) {
        int op; cin >> op;
        if(op == 1) {
            int l, r;
            ull x;
            cin >> l >> r >> x;
            modify(1, l, r, x);
        } else if(op == 2) {
            int s;
            ull x;
            cin >> s >> x;
            modify(1, s, x);
        } else {
            int l, r;
            cin >> l >> r;
            pair<ull, ull> t = ask(1, l, r);
            auto [A, B] = t;

            ull ans = A;
            B &= MAX;
            if (B != 0) {
                int p = HighBit(B);
                int pos = Find(1, l, r, p);
                // cerr << A << ' ' << B << ' ' << p << '\n';
                
                ans = MAX;
                if (pos > l) ans &= ask(1, l, pos - 1).first;
                if (pos < r) ans &= ask(1, pos + 1, r).first;
            }
            cout << ans << '\n';
        }
        // for (int i = 1; i <= n; i++) {
        //     cerr << ask(1, i, i).first << ' ' << ask(1, i, i).second << ",\n"[i == n];
        // }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;

    while(T--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5620kb

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: 0
Accepted
time: 1ms
memory: 5664kb

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
35184908959744
176025477579040
8795942500783873690

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5624kb

input:

100 100
4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...

output:

576531121047601152
1
576460752303423488
4263579105072360993
1306043896232411137
4263579105072360993
576531121047601152
633397148123136
0
1153488865559840256
1153489407883150848
1730020640668059136
3533641810948498945
562958610464768
1730020640668059136
0
633397148123136
4263579105072360993
0
1730020...

result:

wrong answer 11th lines differ - expected: '1152922054496880128', found: '1153489407883150848'