Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- using ll = long long;
- #define endl '\n'
- const int N = 2e5 + 10;
- const int sz = 30;
- const int INF = 0x3f3f3f3f;
- class Segment {
- private:
- struct Node {
- int sum[sz];
- int minst, minnd;
- int minnum;
- } node[N << 2];
- int a[N], n;
- public:
- void init (int _n, int b[N]) {
- n = _n;
- for (int i = 1; i <= n; i ++) {
- a[i] = b[i];
- }
- }
- void push_up (int p) {
- int ls = p << 1, rs = p << 1 | 1;
- for (int i = 0; i < sz; i ++) {
- node[p].sum[i] = node[ls].sum[i] + node[rs].sum[i];
- }
- if (node[ls].minst == node[rs].minst) {
- node[p].minnum = node[ls].minnum + node[rs].minnum;
- node[p].minnd = min(node[ls].minnd, node[rs].minnd);
- }
- if (node[ls].minst < node[rs].minst) {
- node[p].minst = node[ls].minst;
- node[p].minnum = node[ls].minnum;
- node[p].minnd = min(node[ls].minnd, node[rs].minst);
- }
- if (node[ls].minst > node[rs].minst) {
- node[p].minst = node[rs].minst;
- node[p].minnum = node[rs].minnum;
- node[p].minnd = min(node[ls].minst, node[rs].minnd);
- }
- }
- void build (int s, int t, int p) {
- if (s == t) {
- for (int i = 0; i < sz; i ++) {
- node[p].sum[i] = (a[s] >> i) & 1;
- }
- node[p].minst = a[s];
- node[p].minnd = INF;
- node[p].minnum = 1;
- }
- int mid = (s + t) >> 1;
- build(s, mid, p << 1);
- build(mid + 1, t, p << 1 | 1);
- push_up(p);
- }
- void push_down (int p) {
- }
- void update (int l, int r, int x, int s, int t, int p) {
- if (x <= node[p].minst) return;
- if (x < node[p].minnd) {
- for (int i = 0; i < sz; i ++) {
- if ((node[p].minst >> i) & 1) {
- node[p].sum[i] -= node[p].minnum;
- }
- if ((x >> i) & 1) {
- node[p].sum[i] += node[p].minnum;
- }
- }
- node[p].minst = x;
- return;
- }
- push_down(p);
- int mid = (s + t) >> 1;
- if (l <= mid) update(l, r, x, s, mid, p << 1);
- if (mid < r) update(l, r, x, mid + 1, t, p << 1 | 1);
- push_up(p);
- }
- int query (int l, int r, int x, int s, int t, int p) {
- if (l <= s && t <= r) {
- return node[p].sum[x];
- }
- push_down(p);
- int mid = (s + t) >> 1;
- int res = 0;
- if (l <= mid) res = query(l, r, x, s, mid, p << 1);
- if (mid < r) res += query(l, r, x, mid + 1, t, p << 1 | 1);
- push_up(p);
- return res;
- }
- int getxor (int l, int r, int s, int t, int p) {
- if (l <= s && t <= r) {
- int res = 0;
- for (int i = 0; i < sz; i ++) {
- if (node[p].sum[i] & 1) res |= (1 << i);
- }
- return res;
- }
- push_down(p);
- int mid = (s + t) >> 1;
- int res = 0;
- if (l <= mid) res = getxor(l, r, s, mid, p << 1);
- if (mid < r) res ^= getxor(l, r, mid + 1, t, p << 1 | 1);
- push_up(p);
- return res;
- }
- };
- Segment seg;
- int n, q;
- int a[N];
- void solve() {
- cin >> n >> q;
- for (int i = 1; i <= n; i ++) {
- cin >> a[i];
- }
- seg.init(n, a);
- seg.build(1, n, 1);
- while (q --) {
- int opt, l, r, x;
- cin >> opt >> l >> r >> x;
- if (opt == 1) {
- } else {
- }
- }
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int _ = 1;
- // cin >> _;
- while(_--)
- solve();
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement