QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768118#9727. Barkley IIIi_wish_a_girl_friendWA 1ms5700kbC++206.8kb2024-11-21 00:44:522024-11-21 00:44:52

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b))
#define pb push_back
#define LNF 1e18
#define INF 0x7fffffff
#define int long long
#define lowbit(x) ((x) & (-x))
#define abs(x) llabs(x)
#define endl '\n'
#define Y() cout << "Yes" << endl
#define N() cout << "No" << endl
const db eps = 1e-9;
const int mod = 9223372036854775807;
const int MAXN = 2e5 + 5;

int val[1000006];
struct node
{
    int num, is, lazy, siz, sum;
} tr[MAXN << 2];
void push_down(int p)
{
    if (tr[p].lazy ^ mod)
    {
        tr[p << 1].lazy &= tr[p].lazy;
        tr[p << 1 | 1].lazy &= tr[p].lazy;
        if (tr[p << 1].siz == 1)
        {
            tr[p << 1].sum &= tr[p].lazy;
            tr[p << 1].num |= (mod ^ tr[p].lazy);
        }
        else
        {
            tr[p << 1].sum &= tr[p].lazy;
            tr[p << 1].is |= (mod ^ tr[p].lazy);
            tr[p << 1].num &= (tr[p].lazy);
        }
        if (tr[p << 1 | 1].siz == 1)
        {
            tr[p << 1 | 1].sum &= tr[p].lazy;
            tr[p << 1 | 1].num |= (mod ^ tr[p].lazy);
        }
        else
        {
            tr[p << 1 | 1].sum &= tr[p].lazy;
            tr[p << 1 | 1].is |= (mod ^ tr[p].lazy);
            tr[p << 1 | 1].num &= (tr[p].lazy);
        }
        tr[p].lazy = mod;
    }
}
void push_up(int p)
{
    tr[p].sum = tr[p << 1].sum & tr[p << 1 | 1].sum;
    tr[p].is = (tr[p << 1].num & tr[p << 1 | 1].num) | tr[p << 1].is | tr[p << 1 | 1].is;
    tr[p].num = (tr[p << 1].num ^ tr[p << 1 | 1].num) & (mod ^ tr[p].is);
}
node merge(node a, node b)
{
    node c;
    c.sum = a.sum & b.sum;
    c.is = (a.num & b.num) | a.is | b.is;
    c.num = (a.num ^ b.num) & (mod ^ c.is);
    // cout << a.num << " " << b.num << endl;
    return c;
}
void build(int p, int l, int r)
{
    tr[p].siz = r - l + 1;
    tr[p].lazy = mod;
    if (l == r)
    {
        tr[p].num = (mod ^ val[l]);
        tr[p].sum = val[l];
        return;
    }
    int mid = l + r >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    push_up(p);
    // if (l == 6 && r == 9)
    // {
    //     cout << "!" << tr[p].num << endl;
    // }
}
void modify(int p, int l, int r, int pos, int nu)
{
    if (l == r)
    {
        tr[p].sum = nu;
        tr[p].num = (mod ^ nu);
        return;
    }
    push_down(p);
    int mid = l + r >> 1;
    if (pos <= mid)
        modify(p << 1, l, mid, pos, nu);
    else
        modify(p << 1 | 1, mid + 1, r, pos, nu);
    push_up(p);
}
void modify_and(int p, int l, int r, int ql, int qr, int nu)
{
    if (l >= ql && r <= qr)
    {
        if (tr[p].siz == 1)
        {
            tr[p].sum &= nu;
            tr[p].num |= (mod ^ nu);
        }
        else
        {
            tr[p].sum &= nu;
            tr[p].lazy &= nu;
            tr[p].num &= nu;
            tr[p].is |= (mod ^ nu);
        }
        return;
    }
    push_down(p);
    int mid = l + r >> 1;
    if (ql <= mid)
        modify_and(p << 1, l, mid, ql, qr, nu);
    if (qr > mid)
        modify_and(p << 1 | 1, mid + 1, r, ql, qr, nu);
    push_up(p);
}

node query_bit(int p, int l, int r, int ql, int qr)
{
    if (l >= ql && r <= qr)
    {
        return tr[p];
    }
    push_down(p);
    int mid = l + r >> 1;
    node ans = {0, 0, 0, 0, mod};
    if (ql <= mid)
        ans = merge(ans, query_bit(p << 1, l, mid, ql, qr));
    if (qr > mid)
        ans = merge(ans, query_bit(p << 1 | 1, mid + 1, r, ql, qr));
    push_up(p);
    return ans;
}
int query_pos(int p, int l, int r, int ql, int qr, int nu)
{ // 已经被提取的最高位
    if (l == r)
    {
        if(!(tr[p].is & nu) && !(tr[p].sum & nu))
        return l;
    }
    push_down(p);
    int mid = l + r >> 1;
    int ans = 0;
    if (l >= ql && r <= qr)
    {
        if (!(tr[p << 1].is & nu) && !(tr[p << 1].sum & nu))
        {
            ans |= query_pos(p << 1, l, mid, ql, qr, nu);
        }
        if (!(tr[p << 1 | 1].is & nu) && !(tr[p << 1 | 1].sum & nu))
        {
            ans |= query_pos(p << 1 | 1, mid + 1, r, ql, qr, nu);
        }
    }
    else
    {
        if (ql <= mid)
            ans |= query_pos(p << 1, l, mid, ql, qr, nu);
        if (qr > mid)
            ans |= query_pos(p << 1 | 1, mid + 1, r, ql, qr, nu);
    }
    push_up(p);
    return ans;
}
int query_val(int p, int l, int r, int ql, int qr)
{
    if (l >= ql && r <= qr)
    {
        return tr[p].sum;
    }
    push_down(p);
    int mid = l + r >> 1;
    int ans = mod;
    if (ql <= mid)
        ans &= query_val(p << 1, l, mid, ql, qr);
    if (qr > mid)
        ans &= query_val(p << 1 | 1, mid + 1, r, ql, qr);
    push_up(p);
    return ans;
}
void solve()
{
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
        cin >> val[i];
    build(1, 1, n);
    while (q--)
    {
        int op;
        cin >> op;
        if (op == 1)
        {
            int l, r, x;
            cin >> l >> r >> x;
            modify_and(1, 1, n, l, r, x);
        }
        else if (op == 2)
        {
            int s, x;
            cin >> s >> x;
            modify(1, 1, n, s, x);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            if (l == r)
            {
                cout << 0 << endl;
                continue;
            }
            node nu = query_bit(1, 1, n, l, r);
            // cout << nu.sum << endl;
            // cout << nu.num << endl;
            // cout << nu.is << endl;
            int res = ((nu.is | nu.sum) ^ mod) & mod;
            // cout << res << endl;
            int ws = -1;
            for (int i = 62; i >= 0; i--)
            {
                if (res & (1ll << i))
                {
                    ws = i;
                    break;
                }
            }
            // cout << ws << endl;

            if (ws == -1)
            {
                cout << nu.sum << endl;
                continue;
            }
            int pos = query_pos(1, 1, n, l, r, (1ll << ws));
            // cout << pos << endl;
            int ans = mod;
            if (pos != l)
            {
                ans &= query_val(1, 1, n, l, pos - 1);
            }
            if (pos != r)
            {
                ans &= query_val(1, 1, n, pos + 1, r);
            }
            cout << ans << endl;
        }
    }
    // cout << -1 << endl;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << -1 << endl;
    int T = 1;
    // cout << (!(0)) << endl;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5680kb

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
0

result:

wrong answer 4th lines differ - expected: '8795942500783873690', found: '0'