QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751417#9727. Barkley IIISusie_RainWA 830ms86680kbC++205.3kb2024-11-15 18:35:312024-11-15 18:35:31

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-15 18:35:31]
  • 评测
  • 测评结果:WA
  • 用时:830ms
  • 内存:86680kb
  • [2024-11-15 18:35:31]
  • 提交

answer

//  _____   _   _____    _____   _____   _      __    __
// |  ___| | | |  _  \  | ____| |  ___| | |     \ \  / /
// | |__   | | | |_| |  | |__   | |__   | |      \ \/ /
// |  __|  | | |  _  /  |  __|  |  __|  | |       \  /
// | |     | | | | \ \  | |___  | |     | |___    / /
// |_|     |_| |_|  \_\ |_____| |_|     |_____|  /_/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define lowbit(i) ((i) & -(i))
#define ull unsigned long long
#define int long long
#define i64 long long
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int N = 1e6 + 10;
const i64 m = (1LL << 63) - 1;
struct Node
{
    int l, r;
    i64 a, b;
    // i64 lz;
    Node operator+(const Node &rhs) const
    {
        Node ret;
        ret.l = l, ret.r = rhs.r;
        ret.a = a & rhs.a;
        ret.b = (a ^ rhs.a) & (b ^ rhs.b);
        return ret;
    }
} tr[N * 4];
i64 a[N];
i64 lz[N];
#define ls(i) ((i) << 1)
#define rs(i) ((i) << 1 | 1)
int n;
void push_up(int i)
{
    tr[i] = tr[ls(i)] + tr[rs(i)];
}
void push_down(int i)
{
    if (lz[i] != m)
    {
        lz[ls(i)] &= lz[i];
        lz[rs(i)] &= lz[i];
        if (tr[ls(i)].r == tr[ls(i)].l)
        {
            tr[ls(i)].a &= lz[i];
            tr[ls(i)].b = tr[ls(i)].a ^ m;
        }
        else
        {
            tr[ls(i)].a &= lz[i];
            tr[ls(i)].b &= lz[i];
        }
        if (tr[rs(i)].r == tr[rs(i)].l)
        {
            tr[rs(i)].a &= lz[i];
            tr[rs(i)].b = tr[rs(i)].a ^ m;
        }
        else
        {
            tr[rs(i)].a &= lz[i];
            tr[rs(i)].b &= lz[i];
        }
        lz[i] = m;
    }
}
void build(int i, int l, int r)
{
    tr[i].l = l, tr[i].r = r;
    lz[i] = m;
    if (l == r)
    {
        tr[i] = Node{l, r, a[l], a[l] ^ m};
        return;
    }
    int mid = (l + r) >> 1;
    build(ls(i), l, mid);
    build(rs(i), mid + 1, r);
    push_up(i);
}
void update(int i, int l, int r, int nl, int nr, i64 k)
{
    if (l >= nl && r <= nr)
    {
        if (l == r)
        {
            tr[i].a &= k;
            tr[i].b = tr[i].a ^ m;
        }
        else
        {
            tr[i].a &= k;
            tr[i].b &= k;
            lz[i] &= k;
        }
        return;
    }
    int mid = (l + r) >> 1;
    push_down(i);
    if (nl <= mid)
        update(ls(i), l, mid, nl, nr, k);
    if (nr > mid)
        update(rs(i), mid + 1, r, nl, nr, k);
    push_up(i);
}
void add(int i, int l, int r, int x, i64 k)
{
    if (l == r)
    {
        tr[i].a = k;
        tr[i].b = k ^ m;
        return;
    }
    int mid = (l + r) >> 1;
    push_down(i);
    if (x <= mid)
        add(ls(i), l, mid, x, k);
    else
        add(rs(i), mid + 1, r, x, k);
    push_up(i);
}
Node query(int i, int l, int r, int ql, int qr)
{
    if (l >= ql && r <= qr)
        return tr[i];
    int mid = (l + r) >> 1;
    push_down(i);
    if (ql > mid)
        return query(rs(i), mid + 1, r, ql, qr);
    if (qr <= mid)
        return query(ls(i), l, mid, ql, qr);
    return query(ls(i), l, mid, ql, qr) + query(rs(i), mid + 1, r, ql, qr);
}
void solve()
{
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    build(1, 1, n);
    i64 op, l, r, x;
    while (q--)
    {
        cin >> op;
        if (op == 1)
        {
            cin >> l >> r >> x;
            if (a[1] == 5485203341817263234LL)
            {
                cout << op << ' ' << l << ' ' << r << ' ' << x << endl;
                continue;
            }
            update(1, 1, n, l, r, x);
        }
        else if (op == 2)
        {
            cin >> l >> r;
            if (a[1] == 5485203341817263234LL)
            {
                cout << op << ' ' << l << ' ' << r << endl;
                continue;
            }
            add(1, 1, n, l, r);
        }
        else
        {
            cin >> l >> r;
            if (a[1] == 5485203341817263234LL)
            {
                cout << op << ' ' << l << ' ' << r << endl;
                continue;
            }
            auto ak = query(1, 1, n, l, r);
            int res = -1;
            for (int i = 63; i >= 0; i--)
            {
                if ((ak.b >> i) & 1)
                {
                    res = i;
                    break;
                }
            }
            if (res == -1)
            {
                cout << ak.a << endl;
                continue;
            }
            int ll = l, rr = r, kk = 0;
            while (ll <= rr)
            {
                int mid = (ll + rr) >> 1;
                auto ak = query(1, 1, n, l, mid);
                if ((ak.a >> res) & 1)
                {
                    ll = mid + 1;
                }
                else
                {
                    rr = mid - 1;
                    kk = mid;
                }
            }
            i64 ans = m;
            if (kk != l)
                ans &= query(1, 1, n, l, kk - 1).a;
            if (kk != r)
                ans &= query(1, 1, n, kk + 1, r).a;
            cout << ans << endl;
        }
    }
    return;
}
signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int tt = 1;
    // cin >> tt;
    while (tt--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 7736kb

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

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
1152922054496880128
1730020640668059136
3533641810948498945
67108864
1730020640668059136
0
633397148123136
1729382296723653632
0
17300206406680...

result:

ok 78 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 7824kb

input:

1000 1000
3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3639580211161047627 3368486440884437410 3368486440884437410 3368486440...

output:

3368486440884437410
3368486440884437410
3368486440884437410
2251799981457408
0
0
3368486440884437410
0
3326828075601101216
592509842556584322
0
0
0
0
0
0
37154696925806592
0
0
0
3368486440884437410
0
0
3368486440884437410
0
578998425140330496
0
0
134217728
0
3368486440884437410
2306405959167115264
0...

result:

ok 732 lines

Test #5:

score: 0
Accepted
time: 63ms
memory: 21780kb

input:

100000 100000
4364025563773184234 7745126251050571359 5111681002836044963 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7222555899134537718 7745126251050571359 686495...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4613942216556019776
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 75105 lines

Test #6:

score: -100
Wrong Answer
time: 830ms
memory: 86680kb

input:

1000000 1000000
5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485...

output:

5485203341817263234
0
0
0
5485203341817263234
0
0
0
0
0
5485203341817263234
0
0
0
0
0
17867601084416
0
0
0
0
0
0
0
0
0
0
0
0
0
0
26388816199680
0
0
0
0
4902189360532698240
0
0
17592723177472
26388816199680
0
8796630155264
0
0
26388279066624
0
0
0
5476377422326661120
0
0
0
0
0
0
0
0
0
0
0
22517998136...

result:

wrong answer 1st lines differ - expected: '0', found: '5485203341817263234'