QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378267#6427. Just Another Game of StonesUnrealityRE 0ms110324kbC++143.2kb2024-04-06 10:35:422024-04-06 10:35:42

Judging History

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

  • [2024-04-06 10:35:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:110324kb
  • [2024-04-06 10:35:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;

int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); } 
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); } 
const int kN = 200500; 
int a[kN];
using cnt_t = array<int, 30>;
cnt_t operator + (const cnt_t &a, const cnt_t &b) {
	cnt_t res;
	_rep(i,0,29) res[i] = a[i] + b[i];
	return res;
} 
struct Node {
	cnt_t cnt;
	int mn, mncnt, semn, tg;
	void apply(int v) {
		if(v < mn) return;
		//mn => v
		_rep(i,0,29) if(mn & (1 << i)) cnt[i] -= mncnt;
		mn = tg = v;
		_rep(i,0,29) if(mn & (1 << i)) cnt[i] += mncnt;
	}
	Node() : tg(-1) {}
} t[kN << 2];
void pushup(int x) {
	t[x].cnt = t[x << 1].cnt + t[x << 1 | 1].cnt;
	if(t[x << 1].mn < t[x << 1 | 1].mn) {
		t[x].mn = t[x << 1].mn, t[x].mncnt = t[x << 1].mncnt;
		t[x].semn = min(t[x << 1].semn, t[x << 1 | 1].mn);
	} else if(t[x << 1].mn > t[x << 1 | 1].mn) {
		t[x].mn = t[x << 1 | 1].mn, t[x].mncnt = t[x << 1 | 1].mncnt;
		t[x].semn = min(t[x << 1].mn, t[x << 1 | 1].semn);
	} else {
		t[x].mn = t[x << 1].mn, t[x].mncnt = t[x << 1].mncnt + t[x << 1 | 1].mncnt;
		t[x].semn = min(t[x << 1].semn, t[x << 1 | 1].semn);
	}
}
void build(int x, int L, int R) {
	if(L == R) {
		t[x].mn = a[L], t[x].semn = 0x3f3f3f3f, t[x].mncnt = 1;
		_rep(i,0,29) if(a[L] & (1 << i)) ++t[x].cnt[i];
		return;
	}
	build(x << 1, L, mid), build(x << 1 | 1, mid + 1, R);
	pushup(x);
}
void pushdown(int x) {
	if(t[x].tg != -1) {
		t[x << 1].apply(t[x].tg);
		t[x << 1 | 1].apply(t[x].tg);
		t[x].tg = -1;
	}
} 
void RESET(int x, int y) {
	if(t[x].mn >= y) return;
	if(t[x].mn < y && y < t[x].semn) { t[x].apply(y); return; } 
	pushdown(x); RESET(x << 1, y), RESET(x << 1 | 1, y);
	pushup(x);
}
void modify(int x, int L, int R, int l, int r, int v) {
	if(l <= L && R <= r) { RESET(x, v); return;	}
	pushdown(x);
	if(l <= mid) modify(x << 1, L, mid, l, r, v);
	if(mid < r) modify(x << 1 | 1, mid + 1, R, l, r, v);
	pushup(x);
} 
cnt_t query(int x, int L, int R, int l, int r) {
	if(l <= L && R <= r) return t[x].cnt;
	pushdown(x);
	if(r <= mid) return query(x << 1, L, mid, l, r);
	if(mid < l) return query(x << 1 | 1, mid + 1, R, l, r);
	return query(x << 1, L, mid, l, r) + query(x << 1 | 1, mid + 1, R, l, r);
} 
int main() {
	int n = in(), m = in();
	_rep(i,1,n) a[i] = in();
	build(1, 1, n); 
	_rep(i,1,m) {
		int op = in(), l = in(), r = in(), x = in();
		if(op == 1) modify(1, 1, n, l, r, x);
		if(op == 2) {
			cnt_t v = query(1, 1, n, l, r);
			_rep(j,0,29) if(x & (1 << j)) ++v[j];
			int top = -1;
			_rep(j,0,29) if(v[j] & 1) top = j;
			if(top == -1) outln(0);
			else outln(v[top]);
			
		}
	}
	return 0;
}

详细

Test #1:

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

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

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:


result: