QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378269 | #6427. Just Another Game of Stones | Unreality | WA | 166ms | 111164kb | C++14 | 3.2kb | 2024-04-06 10:36:36 | 2024-04-06 10:36:37 |
Judging History
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 = 0x7fffffff, 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 && n <= 10) 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: 110400kb
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
Wrong Answer
time: 166ms
memory: 111164kb
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:
38889 57353 46659 19709 28963 92781 2495 581 9977 29423 6981 6197 16759 8359 20899 10531 48649 8395 32445 351 16447 12571 75233 8761 38317 27901 9821 46705 24637 11251 15631 4903 18363 47913 93327 19763 1341 2993 6981 12827 4547 17969 19911 55845 75941 27253 60677 83117 51089 86783 7669 50173 37931 ...
result:
wrong answer 5th numbers differ - expected: '34617', found: '28963'