QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751474 | #9727. Barkley III | Susie_Rain | WA | 1ms | 9788kb | C++20 | 5.9kb | 2024-11-15 18:56:16 | 2024-11-15 18:56:17 |
Judging History
answer
// _____ _ _____ _____ _____ _ __ __
// | ___| | | | _ \ | ____| | ___| | | \ \ / /
// | |__ | | | |_| | | |__ | |__ | | \ \/ /
// | __| | | | _ / | __| | __| | | \ /
// | | | | | | \ \ | |___ | | | |___ / /
// |_| |_| |_| \_\ |_____| |_| |_____| /_/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define lowbit(i) ((i) & -(i))
#define ull unsigned long long
// #define int long long
#define i64 long long
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int N = 1e6 + 10;
const i64 m = (1LL << 63) - 1;
struct Node
{
int l, r;
i64 a, b;
// i64 lz;
Node operator+(const Node &rhs) const
{
Node ret;
ret.l = l, ret.r = rhs.r;
ret.a = a & rhs.a;
ret.b = (a ^ rhs.a) & (b ^ rhs.b);
return ret;
}
} tr[N * 4];
i64 a[N];
i64 lz[N * 4];
#define ls(i) ((i) << 1)
#define rs(i) ((i) << 1 | 1)
int n;
void push_up(int i)
{
tr[i] = tr[ls(i)] + tr[rs(i)];
}
void push_down(int i)
{
if (lz[i] != m)
{
lz[ls(i)] &= lz[i];
lz[rs(i)] &= lz[i];
if (tr[ls(i)].r == tr[ls(i)].l)
{
tr[ls(i)].a &= lz[i];
tr[ls(i)].b = tr[ls(i)].a ^ m;
}
else
{
tr[ls(i)].a &= lz[i];
tr[ls(i)].b &= lz[i];
}
if (tr[rs(i)].r == tr[rs(i)].l)
{
tr[rs(i)].a &= lz[i];
tr[rs(i)].b = tr[rs(i)].a ^ m;
}
else
{
tr[rs(i)].a &= lz[i];
tr[rs(i)].b &= lz[i];
}
lz[i] = m;
}
}
void build(int i, int l, int r)
{
tr[i].l = l, tr[i].r = r;
lz[i] = m;
if (l == r)
{
tr[i] = Node{l, r, a[l], a[l] ^ m};
return;
}
int mid = (l + r) >> 1;
build(ls(i), l, mid);
build(rs(i), mid + 1, r);
push_up(i);
}
void update(int i, int l, int r, int nl, int nr, i64 k)
{
if (l >= nl && r <= nr)
{
if (l == r)
{
tr[i].a &= k;
tr[i].b = tr[i].a ^ m;
}
else
{
tr[i].a &= k;
tr[i].b &= k;
lz[i] &= k;
}
return;
}
int mid = (l + r) >> 1;
push_down(i);
if (nl <= mid)
update(ls(i), l, mid, nl, nr, k);
if (nr > mid)
update(rs(i), mid + 1, r, nl, nr, k);
push_up(i);
}
void add(int i, int l, int r, int x, i64 k)
{
if (l == r)
{
tr[i].a = k;
tr[i].b = k ^ m;
return;
}
int mid = (l + r) >> 1;
push_down(i);
if (x <= mid)
add(ls(i), l, mid, x, k);
else
add(rs(i), mid + 1, r, x, k);
push_up(i);
}
Node query(int i, int l, int r, int ql, int qr)
{
if (l >= ql && r <= qr)
return tr[i];
int mid = (l + r) >> 1;
push_down(i);
if (ql > mid)
return query(rs(i), mid + 1, r, ql, qr);
if (qr <= mid)
return query(ls(i), l, mid, ql, qr);
return query(ls(i), l, mid, ql, qr) + query(rs(i), mid + 1, r, ql, qr);
}
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline char getc()
{
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? 0 : *p1++;
}
template <typename T>
void Cin(T &a)
{
T ans = 0;
bool f = 0;
char c = getc();
for (; c < '0' || c > '9'; c = getc())
{
if (c == '-')
f = -1;
}
for (; c >= '0' && c <= '9'; c = getc())
{
ans = ans * 10 + c - '0';
}
a = f ? -ans : ans;
}
template <typename T, typename... Args>
void Cin(T &a, Args &...args)
{
Cin(a), Cin(args...);
}
template <typename T>
void Cout(T x)
{ // 注意,这里输出不带换行
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Cout(x / 10);
putchar(x % 10 + '0');
}
void solve()
{
int n, q;
// cin >> n >> q;
Cin(n, q);
for (int i = 1; i <= n; i++)
{
// cin >> a[i];
Cin(a[i]);
}
build(1, 1, n);
i64 op, l, r, x;
while (q--)
{
// cin >> op;
Cin(op);
if (op == 1)
{
// cin >> l >> r >> x;
Cin(l, r, x);
update(1, 1, n, l, r, x);
}
else if (op == 2)
{
// cin >> l >> r;
Cin(l, r);
add(1, 1, n, l, r);
}
else
{
// cin >> l >> r;
Cin(l, r);
auto ak = query(1, 1, n, l, r);
int res = -1;
for (int i = 63; i >= 0; i--)
{
if ((ak.b >> i) & 1)
{
res = i;
break;
}
}
if (res == -1)
{
// cout << ak.a << endl;
Cout(ak.a);
continue;
}
int ll = l, rr = r, kk = 0;
while (ll <= rr)
{
int mid = (ll + rr) >> 1;
auto ak = query(1, 1, n, l, mid);
if ((ak.a >> res) & 1)
{
ll = mid + 1;
}
else
{
rr = mid - 1;
kk = mid;
}
}
i64 ans = m;
if (kk != l)
ans &= query(1, 1, n, l, kk - 1).a;
if (kk != r)
ans &= query(1, 1, n, kk + 1, r).a;
// cout << ans << endl;
Cout(ans);
putchar('\n');
}
}
return;
}
signed main()
{
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// int tt = 1;
// // cin >> tt;
// while (tt--)
// {
solve();
// }
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9788kb
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 33 8
result:
wrong answer 4th lines differ - expected: '3', found: '33'