QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791119#9727. Barkley IIIucup-team4906#WA 1ms7732kbC++174.5kb2024-11-28 16:58:142024-11-28 16:58:15

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-28 16:58:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7732kb
  • [2024-11-28 16:58:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define Sz(x) ((int)((x).size()))
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<int>;
using vll = vector<vl>;
using ull = unsigned long long;

#define N 1000010

int n, q;
const ull U = -1;
ull a[N];
int st[N], top;
struct node
{
    ull sum, tag, val;
}t[N << 2];

#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((l + r) >> 1)

void pushup(node &c, const node a, const node b)
{
    c.sum = a.sum & b.sum;
    c.val = (a.val & b.sum) | (a.sum & b.val);
}

void build(int l, int r, int x)
{
    t[x].tag = U;
    if (l == r) {t[x].sum = a[l]; t[x].val = (U ^ a[l]); return ;}
    build(l, mid, ls); build(mid + 1, r, rs);
    pushup(t[x], t[ls], t[rs]);
    // cout << "GG:" << l << ' ' << r << ' ' << t[x].val << endl;
}
void push(int x, int l, int r, ull w)
{
    t[x].sum = t[x].sum & w;
    t[x].tag = t[x].tag & w;
    if (l == r) t[x].val = (U ^ t[x].sum);
    else t[x].val = t[x].val ^ ((t[x].val) & (U ^ w));
}
void pushdown(int x, int l, int r)
{
    if (t[x].tag != U)
    {
        push(ls, l, mid, t[x].tag);
        push(rs, mid + 1, r, t[x].tag);
        t[x].tag = U;
    }
}
void upd(int l, int r, int x, int ql, int qr, ull W)
{
    if (l == ql && r == qr) {push(x, l, r, W); return ;}
    pushdown(x, l, r);
    if (qr <= mid) upd(l, mid, ls, ql, qr, W);
    else if (ql > mid)upd(mid + 1, r, rs, ql, qr, W);
    else
    {
        upd(l, mid, ls, ql, mid, W);
        upd(mid + 1, r, rs, mid + 1, qr, W);
    }
    pushup(t[x], t[ls], t[rs]);
}
void upd(int l, int r, int x, int pos, ull W)
{
    if (l == r) {t[x].sum = W; t[x].val = U ^ W; return ;}
    pushdown(x, l, r);
    if (pos <= mid)upd(l, mid, ls, pos, W);
    else upd(mid + 1, r, rs, pos, W);
    pushup(t[x], t[ls], t[rs]);
}
void qry(int l, int r, int x, int ql, int qr)
{
    if (l == ql && r == qr) {st[++ top] = x; return ;}
    pushdown(x, l, r);
    if (qr <= mid)qry(l, mid, ls, ql, qr);
    else if (ql > mid)qry(mid + 1, r, rs, ql, qr);
    else {qry(l, mid, ls, ql, mid); qry(mid + 1, r, rs, mid + 1, qr);}
}
node qry(int l, int r)
{
    if (l > r) {node ans; ans.sum = U; return ans;}
    top = 0; qry(1, n, 1, l, r);
    // cout << "EEE:" << l << ' ' << r << ' ' << top << endl;
    // for (int i = 1; i <= top; i ++) cout << st[i] << ' '; cout << endl;
    node ans = t[st[1]], nxt;
    for (int i = 2; i <= top; i ++)pushup(nxt, ans, t[st[i]]), ans = nxt;
    return ans;
}
int Find(int l, int r, int x, int ql, int qr, ull W)
{
    if (l == ql && r == qr)
    {
        if (l == r)return l;
        if (!(t[rs].sum & W))return Find(mid + 1, r, rs, mid + 1, qr, W);
        else if(!(t[ls].sum & W))return Find(l, mid, ls, ql, mid, W);
        else return -1;
    }
    if (qr <= mid) return Find(l, mid, ls, ql, qr, W);
    else if (ql > mid)return Find(mid + 1, r, rs, ql, qr, W);
    else
    {
        int temp = Find(l, mid, ls, ql, mid, W);
        if (temp == -1)return Find(mid + 1, r, rs, mid + 1, qr, W);
        else return temp;
    }
}
void solve()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i ++)cin >> a[i];
    build(1, n, 1);
    // cout << "EE:" << t[1].sum << endl;

    while (q --)
    {
        int op; cin >> op;
        if (op == 1)
        {
            int l, r; ull x;
            cin >> l >> r >> x;
            upd(1, n, 1, l, r, x);
        }
        if (op == 2)
        {
            int x; ull v;
            cin >> x >> v;
            upd(1, n, 1, x, v);
        }
        if (op == 3)
        {
            int l, r;
            cin >> l >> r;
            node temp = qry(l, r);
            // cout << "??:" << l << ' ' << r << " " << temp.val << ' ' << temp.sum << endl;
            if (temp.val == 0) {cout << temp.sum << '\n';}
            else 
            {
                int x = 0;
                for (int i = 63; i >= 0; i --) if ((temp.val >> i) & 1)
                {
                    x = Find(1, n, 1, l, r, (1ULL << i));
                    break;
                }
                assert(x != -1);
                cout << (qry(l, x - 1).sum & qry(x + 1, r).sum) << '\n';
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++)
        solve();

    return 0;
}

/*
 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
*/

详细

Test #1:

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

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: 0ms
memory: 7648kb

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

input:

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

output:

576531121047601152
0
0
3612454262104133153
153122391625564161
4263579105072360993
70368744177664
633397148123136
0
12952010752
1152922054496880128
1730020640668059136
3458764518266578433
67108864
576531718266945536
0
77309673472
1729382296723653632
0
1730020640668059136
3533641810948498945
0
0
17300...

result:

wrong answer 2nd lines differ - expected: '1', found: '0'