RE on test2求助,调了一天了
查看原帖
RE on test2求助,调了一天了
1236247
Da_Vinci楼主2024/12/26 13:30

record

rt,貌似是越界但是不知道哪里挂了,本地在windows和linux环境都经过几百组对拍,也开了fsanitize

#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define il inline
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ld long double
#define db double
#define gc getchar();
#define pc(x) putchar(x)
#define O(x) cout<<x<<'\n';
#define adde(x,y) emplace_back(make_pair(x,y))
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define inline

#define pbset(typ) tree< typ ,null_type,std::less< typ >, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define pbmap(typ1,typ2) tree< typ1 , typ2 ,std::less< typ1 >, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>

namespace constant_warrior {
	template<typename T> inline void fr(T& num) {
		num = 0;
		short sign = 1;
		char ch = std::getchar();
		while (ch < '0' || ch > '9') {
			if (ch == '-')sign = -1;
			ch = std::getchar();
		}
		while (ch >= '0' && ch <= '9')num = num * 10 + ch - '0', ch = getchar();
		num = num*sign;
	}
	template<typename T>inline void fw(T x) {
		if (x < 0)std::putchar('-'), x = -x;
		if (x > 9)fw(x / 10);
		std::putchar(x % 10 + '0');
	}
	template<typename T>inline const T& maxf(const T& a, const T& b) {
		if (a > b)return a;
		return b;
	}
	template<typename T>inline const T& minf(const T& a, const T& b) {
		if (a > b)return b;
		return a;
	}
	template<typename T>inline void swapf(T& a, T& b) {
		a ^= b ^= a ^= b;
	}
}
using namespace constant_warrior;
const int N = 1 << 18;
int n, q, a[N];
namespace seg {
	struct node {
		int mi, sm, cnt, val, lz = -1;
		int bit[32];
		inline void operator+=(int v) {
//			cerr<<" "<<mi<<' '<<v<<'\n';
			if (mi >= v)return;
			if (cnt & 1)val ^= mi, val ^= v;
			for (int i = 0; i <= 30; i++) {
				if (mi >> i & 1)bit[i] -= cnt;
				if (v >> i & 1) bit[i] += cnt;
			}
			mi = lz = v;
		}
	};
	struct seg_node {
		int l, r;
		node info;
	} t[N << 2];
#define ls(p) p<<1
#define rs(p) p<<1|1
	inline node operator+(const node& l, const node& r) {
		node res;
		if (l.mi < r.mi) {
			res.mi = l.mi;
			res.cnt = l.cnt;
			res.sm = min(l.sm, r.mi);
		} else if (l.mi > r.mi) {
			res.mi = r.mi;
			res.cnt = r.cnt;
			res.sm = min(r.sm, l.mi);
		} else {
			res.mi = r.mi;
			res.cnt = r.cnt + l.cnt;
			res.sm = min(r.sm, l.sm);
		}
		res.val = l.val^r.val;
		for (int i = 0; i <= 30; i++)res.bit[i] = l.bit[i] + r.bit[i];
		return res;
	}
	inline void pushup(int p) {
//		assert(p<=8e5);
		t[p].info = t[ls(p)].info + t[rs(p)].info;
	}
	inline void pushdown(int p) {
//		assert(p<=8e5);
		if (t[p].info.lz != -1) {
//			cerr<<"pd\n";
			t[ls(p)].info += t[p].info.lz;
			t[rs(p)].info += t[p].info.lz;
//			cerr<<'\n';
			t[p].info.lz = -1;
		}
	}
	inline void build(int p, int l, int r) {
//		assert(p<=8e5);
//		cerr<<"B "<<p<<' '<<l<<' '<<r<<'\n';
		t[p].info.lz = -1, t[p].l = l, t[p].r = r;
		if (l == r) {
//			cerr<<"???\n";
			t[p].info.mi = t[p].info.val = a[l];
			t[p].info.sm = 0x3f3f3f3f, t[p].info.cnt = 1;
			for (int i = 0; i <= 30; i++)t[p].info.bit[i] += (a[l] >> i & 1);
			return;
		}
		int mid = (l + r) >> 1;
		build(ls(p), l, mid);
		build(rs(p), mid + 1, r);
		pushup(p);
	}
	inline void modify(int p, int l, int r, int v) {
//		assert(p<=8e5);
//		cerr<<"M"<<p<<' '<<t[p].l<<' '<<t[p].r<<'\n';
		if (t[p].info.mi >= v)return;
		if (l <= t[p].l && t[p].r <= r && t[p].info.sm > v)return t[p].info += v;
		int mid = (t[p].l + t[p].r) >> 1;
		pushdown(p);
		if (l <= mid)modify(ls(p), l, r, v);
		if (r > mid) modify(rs(p), l, r, v);
		pushup(p);
	}
	inline node query(int p, int l, int r) {
//		assert(p<=8e5);
//		cerr<<p<<' '<<l<<' '<<r<<' '<<t[p].l<<' '<<t[p].r<<'\n';
		if (l <= t[p].l && t[p].r <= r)return t[p].info;
		pushdown(p);
		int mid = (t[p].l + t[p].r) >> 1;
		if (r <= mid)return query(ls(p), l, r);
		if (l > mid) return query(rs(p), l, r);
		assert(l <= mid&&r > mid);
		return query(ls(p), l, r) + query(rs(p), l, r);
	}
}


void solve() {
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	using namespace seg;
	fr(n), fr(q);
	for (int i = 1; i <= n; i++)fr(a[i]);
	seg::build(1, 1, n);
	while (q-->0) {
		int op, l, r, x;
		fr(op), fr(l), fr(r), fr(x);
		assert(l <= r);
		if (op == 1) {
			modify(1, l, r, x);
		} else {
			node a = query(1, l, r);
			int sum = a.val^x, hb = -1;
//				cerr<<a.val<<'\n';
			for (int i = 30; i >= 0; i--) {
				if (sum >> i & 1) {
					hb = i;
					break;
				}
			}
//			for(int i=0;i<=30;i++)cerr<<a.bit[i]<<' ';cerr<<'\n';
			if (~hb)fw(a.bit[hb] + (x >> hb & 1)), pc('\n');
			else fw(0), pc('\n');
		}
	}



}

int main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	int T = 1; //cin>>T;
	while (T-->0)solve();
}
/*
暴力出奇迹,卡常能AC。
Violent makes miracle,pursuing better constant can AC.
多测不清空,OI见祖宗。
multitesting without clearing,oier meets the LCA.
十年OI一场空,不开LL见祖宗。
Ten years of OI just AFO,no #define int long long sees the LCA.
似是神犇成才处,实为蒟蒻黄泉路。
It is likely to be the Au medal for the big old,but in fact it is the Si medal for me.
黄题有恨无正解,码力不若小学生。
A yellow problem I can't AC,codeforces is not as NB as HNO3(Dilute nitric acid).
今生无奈入OI,来世不做信竞人。
This life I am a Siliy Being in oi,next life I won't f**k the sh*t of infomatics.
*/
2024/12/26 13:30
加载中...