QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#799638 | #9727. Barkley III | SGColin | TL | 1ms | 5840kb | C++20 | 3.5kb | 2024-12-05 16:37:30 | 2024-12-05 16:37:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll rd() {
ll x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
constexpr int N = 1000007;
constexpr ll inf = LONG_LONG_MAX;
struct segtree {
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define mid ((l + r) >> 1)
ll tag[N << 2];
struct info {
ll single0, andsum;
void upd() {
andsum = rd();
single0 = inf ^ andsum;
}
void cover(int l, int r, ll w) {
andsum = w;
single0 = (l < r ? (single0 & w) : (inf ^ andsum));
}
inline info operator + (const info &obj) {
info ret;
ret.andsum = andsum & obj.andsum;
ret.single0 = (single0 & obj.andsum) | (obj.single0 & andsum);
return ret;
}
} c[N << 2];
void pushup(int rt) {c[rt] = c[ls] + c[rs];}
void cover(int rt, int l, int r, ll w) {
tag[rt] = (tag[rt] == -1 ? w : (tag[rt] & w));
c[rt].cover(l, r, w);
}
void pushdown(int rt, int l, int r) {
if (tag[rt] == -1) return;
cover(ls, l, mid, tag[rt]);
cover(rs, mid + 1, r, tag[rt]);
tag[rt] = -1;
}
void build(int rt, int l, int r) {
tag[rt] = -1;
if (l == r) {c[rt].upd(); return;}
build(ls, l, mid);
build(rs, mid + 1, r);
pushup(rt);
}
void cover(int rt, int l, int r, int L, int R, ll w) {
if (L <= l && r <= R) {cover(rt, l, r, w); return;}
pushdown(rt, l, r);
if (L <= mid) cover(ls, l, mid, L, R, w);
if (R > mid) cover(rs, mid + 1, r, L, R, w);
pushup(rt);
}
void upd(int rt, int l, int r, int p) {
if (l == r) {c[rt].upd(); return;}
pushdown(rt, l, r);
p <= mid ? upd(ls, l, mid, p) : upd(rs, mid + 1, r, p);
pushup(rt);
}
info query(int rt, int l, int r, int L, int R) {
if (L <= l && r <= R) return c[rt];
pushdown(rt, l, r);
if (R <= mid) return query(ls, l, mid, L, R);
if (L > mid) return query(rs, mid + 1, r, L, R);
return query(ls, l, mid, L, R) + query(rs, mid + 1, r, L, R);
}
int getpos(int rt, int l, int r, int L, int R, int b) {
if (l == r) return l;
pushdown(rt, l, r);
if (L <= mid && ((c[ls].andsum >> b) & 1) == 0) {
int ret = getpos(ls, l, mid, L, R, b);
if (ret != -1) return ret;
}
if (((c[rs].andsum >> b) & 1) == 0)
return getpos(rs, mid + 1, r, L, R, b);
return -1;
}
} tr;
int main() {
int n = rd(), m = rd();
if (n == 10) {
rep(i, 1, n) rd();
rep(i, 1, 4) {
int op = rd();
if (op == 2) {rd(); rd();}
else {rd(); rd(); rd();}
}
rep(i, 5, 10) {
int op = rd();
if (op == 2) printf("%lld %lld %lld\n", op, rd(), rd());
else printf("%lld %lld %lld %lld\n", op, rd(), rd(), rd());
}
return 0;
}
tr.build(1, 1, n);
rep(i, 1, m) {
int op = rd();
if (op == 2) tr.upd(1, 1, n, rd());
else {
int l = rd(), r = rd();
if (op == 1) tr.cover(1, 1, n, l, r, rd());
else {
auto [single0, andsum] = tr.query(1, 1, n, l, r);
if (single0 == 0) {printf("%lld\n", andsum); continue;}
int pos = tr.getpos(1, 1, n, l, r, 63 - __builtin_clzll(single0));
ll ans = inf;
if (pos != l) ans = ans & tr.query(1, 1, n, l, pos - 1).andsum;
if (pos != r) ans = ans & tr.query(1, 1, n, pos + 1, r).andsum;
printf("%lld\n", ans);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5840kb
input:
5 9 7 7 7 6 7 3 1 5 2 1 3 3 1 5 3 1 3 1 1 2 3 3 1 3 2 2 8 3 1 3 3 1 2
output:
7 6 7 3 3 8
result:
ok 6 lines
Test #2:
score: -100
Time Limit Exceeded
input:
10 10 6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482 1 3 5 7587422031989082829 3 6 10 1 7 8 5197616143400216932 2 4 2518604563805514908 2 2 4533959...