QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864746#9727. Barkley IIIAndyqian7RE 0ms0kbC++203.9kb2025-01-20 23:03:092025-01-20 23:03:10

Judging History

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

  • [2025-01-20 23:03:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2025-01-20 23:03:09]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, s, e) for (int i = s; i <= e; i++)
#define ll long long
using namespace std;
const int N = 1e6 + 10;
struct info
{
    ll f, g;
} tr[N << 2];
int n, q;
ll a[N], lz[N << 2];
info operator+(const info &a, const info &b)
{
    return {a.f | b.f | (~a.g & ~b.g), a.g & b.g};
}
void pushup(int m)
{
    tr[m] = tr[m << 1] + tr[m << 1 | 1];
}
void pushdown(int m, int l, int r)
{
    int mid = l + r >> 1;
    lz[m << 1] &= lz[m], lz[m << 1 | 1] &= lz[m];
    if (mid > l)
    {
        tr[m << 1].f |= ~lz[m];
    }
    tr[m << 1].g &= lz[m];
    if (r > mid + 1)
    {
        tr[m << 1 | 1].f |= ~lz[m];
    }
    tr[m << 1 | 1].g &= lz[m];
    lz[m] = -1;
}
void build(int l, int r, int m)
{
    lz[m] = -1;
    if (l == r)
    {
        tr[m] = {0, a[l]};
        return;
    }
    int mid = l + r >> 1;
    build(l, mid, m << 1), build(mid + 1, r, m << 1 | 1);
    pushup(m);
}
info query(int L, int R, int l, int r, int m)
{
    if (L <= l && r <= R)
    {
        return tr[m];
    }
    pushdown(m, l, r);
    int mid = l + r >> 1;
    info ret = {0, -1};
    if (L <= mid)
        ret = ret + query(L, R, l, mid, m << 1);
    if (R > mid)
        ret = ret + query(L, R, mid + 1, r, m << 1 | 1);
    return ret;
}
void update(int s, ll x, int l, int r, int m)
{
    if (l == r)
    {
        tr[m] = {0, x};
        return;
    }
    pushdown(m, l, r);
    int mid = l + r >> 1;
    if (s <= mid)
        update(s, x, l, mid, m << 1);
    if (s > mid)
        update(s, x, mid + 1, r, m << 1 | 1);
    pushup(m);
}
void update(int L, int R, ll x, int l, int r, int m)
{
    if (L <= l && r <= R)
    {
        lz[m] &= x;
        if (r > l)
        {
            tr[m].f |= ~x;
        }
        tr[m].g &= x;
        return;
    }
    pushdown(m, l, r);
    int mid = l + r >> 1;
    if (L <= mid)
        update(L, R, x, l, mid, m << 1);
    if (R > mid)
        update(L, R, x, mid + 1, r, m << 1 | 1);
    pushup(m);
}
int Find_first(int bit, int low, int l, int r, int m)
{
    if (tr[m].g >> bit & 1)
        return 1e9;
    if (l == r)
    {
        return l;
    }
    int mid = l + r >> 1;
    if (low > mid)
    {
        return Find_first(bit, low, mid + 1, r, m << 1 | 1);
    }
    return min(Find_first(bit, low, l, mid, m << 1), Find_first(bit, low, mid + 1, r, m << 1 | 1));
}
signed main()
{
    freopen("1.in", "r", stdin);
    freopen("11.out", "w", stdout);
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> q;
    rep(i, 1, n) cin >> a[i];
    build(1, n, 1);
    while (q--)
    {
        int tp;
        cin >> tp;
        if (tp == 1)
        {
            int l, r;
            ll x;
            cin >> l >> r >> x;
            update(l, r, x, 1, n, 1);
        }
        else if (tp == 2)
        {
            int s;
            ll x;
            cin >> s >> x;
            update(s, x, 1, n, 1);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            info ret = query(l, r, 1, n, 1);
            int bit = -1;
            rep(i, 0, 62)
            {
                if (~ret.f >> i & 1)
                    if (~ret.g >> i & 1)
                    {
                        bit = i;
                    }
            }
            ll ans = 0;
            if (~bit)
            {
                int ind = Find_first(bit, l, 1, n, 1);
                ll val = query(ind, ind, 1, n, 1).g;
                rep(i, 0, 62)
                {
                    if (ret.g >> i & 1)
                        ans |= 1ll << i;
                    if (~ret.f >> i & 1)
                        if (~val >> i & 1)
                            ans |= 1ll << i;
                }
            }
            else
            {
                ans = ret.g;
            }
            cout << ans << endl;
        }
    }
}

详细

Test #1:

score: 0
Dangerous Syscalls

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:


result: