QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787228#9727. Barkley IIIqinsjRE 0ms3612kbC++204.8kb2024-11-27 10:28:122024-11-27 10:28:24

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-27 10:28:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-27 10:28:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int, int>

#define db(args...){\
    string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << endl;}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ' ';
    err(++it, args...);
}

// 43
const ll S = (1ll << 63) - 1;


template<class Info, class Tag>
struct Segment {
	int n;
	vector<Info> info;
	vector<Tag> tag;
	Segment(int n_, vector<Info> & init) {
		n = n_; info.resize(n * 4 + 10), tag.resize(n * 4 + 10);
		build(1, 1, n, init);
	}
    Segment(int n_) {
        n = n_;
        info.assign(n * 4 + 10, {}), tag.assign(n * 4 + 10, {});
    }
	void build(int u, int l, int r, vector<Info> &init) {
		if(l == r) {info[u] = init[l]; return;}
		int mid = l + r >> 1;
		build(u * 2, l, mid, init); build(u * 2 + 1, mid + 1, r, init);
		info[u] = info[u * 2] + info[u * 2 + 1];
	}
	Info query(int u, int l, int r, int ul, int ur) {
		if(l <= ul && r >= ur) return info[u];
		int mid = ul + ur >> 1;
		push_down(u);
		if(r <= mid) return query(u * 2, l, r, ul, mid);
		if(l > mid) return query(u * 2 + 1, l, r, mid + 1, ur);
		return query(u * 2, l, r, ul, mid) + query(u * 2 + 1, l, r, mid + 1, ur);
	}
	Info query(int l, int r) {
        if (l > r) {
            return {S, S, 0};
        }
		return query(1, l, r, 1, n);
	}
	void push(int v,const Tag & t) {
		tag[v].aply(t); 
		info[v].aply(t);
	}
	void push_down(int u) {
		push(u * 2, tag[u]); push(u * 2 + 1, tag[u]);
		tag[u] = Tag();
	}
	void change(int u, int l, int r, const Tag& x, int ul, int ur) {
		if(l <= ul && r >= ur) {
			push(u, x);
			return;
		}
		int mid = ul + ur >> 1;
		push_down(u);
		if(l <= mid) change(u * 2, l, r, x, ul, mid);
		if(r > mid) change(u * 2 + 1, l, r, x, mid + 1, ur);
		info[u]	= info[u * 2] + info[u * 2 + 1];
	}
	void change(int l, int r, const Tag& x) {
        
		change(1, l, r, x, 1, n);
	}

    void modify(int u, int p, ll v, int l, int r) {
        if (l == r) {
            info[u].modify(v);
            return;
        }
        int mid = l + r >> 1;
        push_down(u);
        if (p <= mid) modify(u * 2, p, v, l, mid);
        else modify(u * 2 + 1, p, v, mid + 1, r);
        info[u] = info[u * 2] + info[u * 2 + 1];
    }
    void modify(int p, ll v) {
        modify(1, p, v, 1, n);
    }

    int find(int u, int l, int r, ll hb, int ul, int ur) {
        // db(ul, ur, hb);
        if (r < ul && l > ur) {
            return -1;
        }
        if (l <= ul && r >= ur) {
            if (info[u].len == 1) {
                return ((hb & info[u].y) ? ul : -1);
            } else {
                if ((info[u].y & hb) == 0) return -1;
            }
        }
        int mid = ul + ur >> 1;
        push_down(u);
        int res = find(u * 2, l, r, hb, ul, mid);
        if (res == -1) res = find(u * 2 + 1, l, r, hb, mid + 1, ur);
        // db(ul, ur, res);
        return res;
    }
};

struct Tag {
    ll v;
    Tag(){v = S;}
    Tag(ll v_) {
        v = v_;
    }
    void aply(const Tag &t) {
        v &= t.v;
    }
};

struct Info {
    ll x, y;
    int len;
    Info operator+(const Info &t) const {
        Info res;
        res.x = x & t.x;
        res.y = (y & t.x) | (x & t.y);
        res.len = len + t.len;
        return res;
    }
    void aply(const Tag &t) {
        x &= t.v;
        if (len == 1) {
            y = x ^ S;
        } else {
            y &= t.v;
        }
    }

    void modify(const ll val) {
        x = val, y = S ^ val, len = 1;
    }

    
};

void show(ll x) {
    cout << bitset<3>(x) << '\n';
}
void solve() {
    int n, m;
    cin >> n >> m;

    vector<Info> init(n + 1);
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        init[i] = {x, S ^ x, 1};
    }
    Segment<Info, Tag> tr(n, init);

    while (m--) {
        ll o, x, y;
        cin >> o >> x >> y;
        if (o == 1) {
            ll v;
            cin >> v;
            tr.change(x, y, {v});
        } else if (o == 2) {
            tr.modify(x, y);
        } else {
            auto info = tr.query(x, y);
            if (info.y == 0) {
                cout << info.x << '\n';
                continue;
            }
            ll hb = 1ll << __lg(info.y);
            int p = tr.find(1, x, y, hb, 1, n);
            cout << (tr.query(x, p - 1).x & tr.query(p + 1, y).x) << '\n';
        }
    }
}
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

/*
g++ 1.cpp -Wall -std=c++20 -o 1 && ./1 < in.txt > out.txt
 */

详细

Test #1:

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

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
Runtime Error

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:


result: