QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739871#9727. Barkley IIIlonelywolfWA 0ms3660kbC++205.9kb2024-11-12 23:35:582024-11-12 23:35:59

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-12 23:35:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-11-12 23:35:58]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  
using ull = unsigned long long;

template<class Info, class Tag>
struct LazySegmentTree {
    int n;
    vector<Info> info;
    vector<Tag> tag;
    LazySegmentTree() : n(0) {}
    LazySegmentTree(int n_, Info v_ = Info()) {
        init(n_, v_);
    }
    template<class T>
    LazySegmentTree(vector<T> init_) {
        init(init_);
    }
    void init(int n_, Info v_ = Info()) {
        init(vector(n_ + 1, v_));
    }
    template<class T>
    void init(vector<T> init_) {
        n = init_.size() - 1;
        info.assign(4 << __lg(n) + 1, Info());
        tag.assign(4 << __lg(n) + 1, Tag());
        function<void(int, int, int)> build = [&](int p, int l, int r) {
            if (l == r) {
                info[p] = init_[l];
                return;
            }
            int m = (l + r) / 2;
            build(2 * p, l, m);
            build(2 * p + 1, m + 1, r);
            pull(p);
        };
        build(1, 1, n);
    }
    void pull(int p) {
        info[p] = info[2 * p] + info[2 * p + 1];
    }
    void apply(int p, const Tag &v) {
        info[p].apply(v);
        tag[p].apply(v);
    }
    void push(int p) {
        apply(2 * p, tag[p]);
        apply(2 * p + 1, tag[p]);
        tag[p] = Tag();
    }
    void modify(int p, int l, int r, int x, const Info &v) {
        if (l == r) {
            info[p] = v;
            return;
        }
        int m = (l + r) / 2;
        push(p);
        if (x <= m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m + 1, r, x, v);
        }
        pull(p);
    }
    void modify(int p, const Info &v) {
        modify(1, 1, n, p, v);
    }
    Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l > y || r < x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return info[p];
        }
        int m = (l + r) / 2;
        push(p);
        return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m + 1, r, x, y);
    }
    Info rangeQuery(int l, int r) {
        return rangeQuery(1, 1, n, l, r);
    }
    void rangeApply(int p, int l, int r, int x, int y, const Tag &v) {
        if (l > y || r < x) {
            return;
        }
        if (l >= x && r <= y) {
            apply(p, v);
            return;
        }
        int m = (l + r) / 2;
        push(p);
        rangeApply(2 * p, l, m, x, y, v);
        rangeApply(2 * p + 1, m + 1, r, x, y, v);
        pull(p);
    }
    void rangeApply(int l, int r, const Tag &v) {
        return rangeApply(1, 1, n, l, r, v);
    }
	template<class F>
    int findFirst(int p, int l, int r, int x, int y, F pred) {
        if (l > y || r < x || !pred(info[p])) {
            return -1;
        }
        if (l == r) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findFirst(2 * p, l, m, x, y, pred);
        if (res == -1) {
            res = findFirst(2 * p + 1, m + 1, r, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findFirst(int l, int r, F pred) {
        return findFirst(1, 1, n, l, r, pred);
    }
    template<class F>
    int findLast(int p, int l, int r, int x, int y, F pred) {
        if (l > y || r < x || !pred(info[p])) {
            return -1;
        }
        if (l == r) {
            return l;
        }
        int m = (l + r) / 2;
        push(p);
        int res = findLast(2 * p + 1, m + 1, r, x, y, pred);
        if (res == -1) {
            res = findLast(2 * p, l, m, x, y, pred);
        }
        return res;
    }
    template<class F>
    int findLast(int l, int r, F pred) {
        return findLast(1, 1, n, l, r, pred);
    }

    // Info query(int p, int l, int r, int x, int y, int pos) {
    // 	if (l > y || r < x || r < l) {
    //         return Info();
    //     }
    //     if (l >= x && r <= y && !(l <= pos && pos <= r)) {
    //         return info[p];
    //     }
    //     int m = (l + r) / 2;
    //     push(p);
    //     Info ret;
    //     if (l <= pos && pos <= m) {
    //     	ret = ret + query(1, 1, n, l, pos - 1, pos);
    //     	ret = ret + query(1, 1, n, x, y, pos);
    //     } else {
    //     	ret = ret + query(2 * p, l, m, x, y, pos);
    //     }
	// 	if (m + 1 <= pos && pos <= r) {
    //     	ret = ret + query(2 * p + 1, m + 1, pos - 1, x, y, pos);
    //     	ret = ret + query(2 * p + 1, pos + 1, r, x, y, pos);
    //     } else {
    //     	ret = ret + query(2 * p + 1, m + 1, r, x, y, pos);
    //     }
    //     return ret;
    // }
};
struct Tag {
	ull val = -1;
    void apply(Tag t) {
    	val &= t.val;
	}
};
struct Info {
	ull val = -1, flg1 = -1, flg2 = 0;
    void apply(Tag t) {
    	val &= t.val;
    	flg2 = (flg2 & t.val) | (flg1 & (~t.val)); 
		flg1 &= t.val;    	
	}
};
Info operator+(Info a, Info b) {
    return {a.val & b.val, a.flg1 & b.flg1, (a.flg1 & b.flg2) | (b.flg1 & a.flg2)};
}

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

	int n, q;
	cin >> n >> q;

	LazySegmentTree<Info, Tag> tr(n);
	for (int i = 1; i <= n; i++) {
		ull x;
		cin >> x;
		tr.modify(i, {x, x, ~x});
	}

	while (q--) {
		int o;
		cin >> o;

		if (o == 1) {
			int l, r;
			ull x;
			cin >> l >> r >> x;
			tr.rangeApply(l, r, {x});
		} else if (o == 2) {
			int p;
			ull x;
			cin >> p >> x;
			tr.modify(p, {x, x, ~x});
		} else {
			int l, r;
			cin >> l >> r;
			auto [v, a, b] = tr.rangeQuery(l, r);
			if (b == 0) {
				cout << v << "\n";
				continue;
			}
			int k = __lg(b);
			int pos = tr.findFirst(l, r, [&](Info p) {
				return !(p.val >> k & 1); 
			});
			Info ans;
			if (pos != l) {
				ans = ans + tr.rangeQuery(l, pos - 1);
			} 
			if (pos != r) {
				ans = ans + tr.rangeQuery(pos + 1, r);
			}

			cout << ans.val << "\n";
		}
	}

    return 0;
}  
  

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3660kb

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
3

result:

wrong answer 6th lines differ - expected: '8', found: '3'