QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176537#6427. Just Another Game of StoneshazeTL 31ms116496kbC++143.7kb2023-09-11 19:27:442023-09-11 19:27:45

Judging History

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

  • [2023-09-11 19:27:45]
  • 评测
  • 测评结果:TL
  • 用时:31ms
  • 内存:116496kb
  • [2023-09-11 19:27:44]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,abm,mmx")
#include<bits/stdc++.h>
#define ll long long
#define irep(i,l,r) for(ll i = l; i <= r; ++i)
using namespace std;
inline int read(){
	int s=0;
	char chcc=getchar();
	while(chcc<'0'||chcc>'9')chcc = getchar();
	while(chcc>='0'&&chcc<='9') s=(s<<3)+(s<<1)+(chcc^48),chcc=getchar();
	return s;
}
const int N = 600999;
const int itinf = 1000000000;
int n, m;
struct node{
	vector<int>bsum;
	int xorsum, mn, smn, len, tag;
	node(){bsum.resize(32);}
}t[N];
/*
void fdmn(vector<int>aa, int &mn, int &smn){
	sort(aa.begin(), aa.end());
	unique(aa.begin(), aa.end());
	mn = aa[0], smn = aa[1];
}
*/
void update(int x){
	t[x].mn = min(t[x << 1].mn, t[x << 1 | 1].mn);
	t[x].smn = itinf;
	if(t[x << 1].mn > t[x].mn)t[x].smn = min(t[x].smn, t[x << 1].mn);
	if(t[x << 1].smn > t[x].mn)t[x].smn = min(t[x].smn, t[x << 1].smn);
	if(t[x << 1 | 1].mn > t[x].mn)t[x].smn = min(t[x].smn, t[x << 1 | 1].mn);
	if(t[x << 1 | 1].smn > t[x].mn)t[x].smn = min(t[x].smn, t[x << 1 | 1].smn);
	
	
//	fdmn({t[x << 1].mn, t[x << 1].smn, t[x << 1 | 1].mn, t[x << 1 | 1].smn}, t[x].mn, t[x].smn);
	t[x].len = 0, t[x].xorsum = t[x << 1].xorsum ^ t[x << 1 | 1].xorsum;
	if(t[x << 1].mn == t[x].mn)t[x].len += t[x << 1 | 1].len;
	if(t[x << 1 | 1].mn == t[x].mn)t[x].len += t[x << 1 | 1].len;
	irep(i,0,31)t[x].bsum[i] = t[x << 1].bsum[i] + t[x << 1 | 1].bsum[i];
}

void operate(int x,int lim){
	if(t[x].len & 1)t[x].xorsum ^= (lim ^ t[x].mn);
	t[x].tag = lim;
	int od = t[x].mn, nw = lim;
	irep(i,0,31){
		t[x].bsum[i] += ((nw & 1) - (od & 1)) * t[x].len;
		nw >>= 1, od >>= 1;
	}
	t[x].mn = lim;
}

void pushdown(int x){
	int tag = t[x].tag;
	t[x].tag = 0;
	if(t[x << 1].mn < tag)operate(x << 1,tag);
	if(t[x << 1 | 1].mn < tag)operate(x << 1 | 1,tag);
}

void build(int x,int l,int r){
	if(l == r){
		int val;
		val = t[x].mn = t[x].xorsum = read();
		t[x].len = 1;
		t[x].smn = t[x].tag = itinf;
		irep(i,0,31){
			t[x].bsum[i] += val & 1;
			val >>= 1;
		}
		return;
	}
	int mid = (l + r) >> 1;
	build(x << 1,l, mid);
	build(x << 1 | 1, mid + 1, r);
	update(x);
	return;
}
void modify(int x,int l,int r,int L,int R, int lim){
	// x -> max(x, val)
	if(l > R || L > r)return;
	if(L <= l && r <= R){
		if(lim <= t[x].mn)return;
		if(l != r && t[x].tag)pushdown(x);
		if(lim < t[x].smn){
			operate(x,lim);
			return;
		}
		int mid = (l + r) >> 1;
		if(l == r)return;
		modify(x << 1,l, mid, L,R,lim);
		modify(x << 1 | 1, mid + 1, r ,L,R,lim);
		update(x);
		return;
	}
	if(l != r && t[x].tag)pushdown(x);
	int mid = (l + r) >> 1;
	modify(x << 1,l, mid, L,R,lim);
	modify(x << 1 | 1, mid + 1, r ,L,R,lim);
	update(x);
	return;
}
int xor_query(int x,int l,int r,int L,int R){
	if(l > R || L > r)return 0;
	if(L <= l && r <= R)return t[x].xorsum;
	if(l != r && t[x].tag)pushdown(x);
	int mid = (l + r) >> 1;
	return xor_query(x << 1,l,mid,L,R) ^ xor_query(x << 1 | 1,mid+1,r,L,R);
}
int bit_cnt(int x,int l, int r, int L ,int R,int id){
	if(l > R || L > r)return 0;
	if(L <= l && r <= R)return t[x].bsum[id];
	if(l != r && t[x].tag)pushdown(x);
	int mid = (l + r) >> 1;
	return bit_cnt(x << 1 ,l,mid,L,R,id) + bit_cnt(x << 1 | 1,mid+1,r,L,R,id);
}
int main(){
	clock_t st = clock();
	n = read(), m = read();
	build(1,1,n);
	while(m --){
		clock_t cur = clock();
		if(cur - st >= 2000000){
			cout << m << endl;
		}
		int op = read(), l = read(), r = read(), x = read();
		if(op == 1){
			modify(1,1,n,l,r,x);
		}else{
			ll key = xor_query(1,1,n,l,r);
			if((key ^ x) == 0){
				puts("0");
				continue;
			}
			int hb = log2(key ^ x);
			ll ans = bit_cnt(1,1,n,l,r,hb);
			if(x & (1 << hb))++ ans;
			if(n <= 10000)printf("%lld\n",ans);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 31ms
memory: 116496kb

input:

5 4
1 2 1 4 1
2 1 3 1
1 2 4 3
2 2 4 4
2 1 4 4

output:

1
0
3

result:

ok 3 number(s): "1 0 3"

Test #2:

score: -100
Time Limit Exceeded

input:

200000 200000
962352030 173642520 1008864183 74920228 684681800 500911321 1001441054 257633652 185843534 59168654 317689197 731348417 123888883 708119712 340055368 876566011 980078202 969174443 814012870 715639041 596932238 173757742 314504576 1045746913 740811577 570187156 999816627 12441059 122507...

output:

171589
171588
171587
171586
171585
171584
171583
171582
171581
171580
171579
171578
171577
171576
171575
171574
171573
171572
171571
171570
171569
171568
171567
171566
171565
171564
171563
171562
171561
171560
171559
171558
171557
171556
171555
171554
171553
171552
171551
171550
171549
171548
171547...

result: