QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768076 | #9727. Barkley III | i_wish_a_girl_friend | WA | 1ms | 5708kb | C++20 | 6.3kb | 2024-11-21 00:13:21 | 2024-11-21 00:13:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b))
#define pb push_back
#define LNF 1e18
#define INF 0x7fffffff
#define int long long
#define lowbit(x) ((x) & (-x))
#define abs(x) llabs(x)
#define endl '\n'
#define Y() cout << "Yes" << endl
#define N() cout << "No" << endl
const db eps = 1e-9;
const int mod = 9223372036854775807;
const int MAXN = 2e5 + 5;
int val[1000006];
struct node
{
int num, is, lazy, siz, sum;
} tr[MAXN << 2];
void push_down(int p)
{
if (tr[p].lazy ^ mod)
{
tr[p << 1].lazy &= tr[p].lazy;
tr[p << 1 | 1].lazy &= tr[p].lazy;
if (tr[p << 1].siz == 1)
{
tr[p << 1].sum &= tr[p].lazy;
tr[p << 1].num |= (mod ^ tr[p].lazy);
}
else
{
tr[p << 1].sum &= tr[p].lazy;
tr[p << 1].is |= (mod ^ tr[p].lazy);
tr[p << 1].num &= (tr[p].lazy);
}
if (tr[p << 1 | 1].siz == 1)
{
tr[p << 1 | 1].sum &= tr[p].lazy;
tr[p << 1 | 1].num |= (mod ^ tr[p].lazy);
}
else
{
tr[p << 1 | 1].sum &= tr[p].lazy;
tr[p << 1 | 1].is |= (mod ^ tr[p].lazy);
tr[p << 1 | 1].num &= (tr[p].lazy);
}
tr[p].lazy = mod;
}
}
void push_up(int p)
{
tr[p].sum = tr[p << 1].sum & tr[p << 1 | 1].sum;
tr[p].is = (tr[p << 1].num & tr[p << 1 | 1].num) | tr[p << 1].is | tr[p << 1 | 1].is;
tr[p].num = (tr[p << 1].num ^ tr[p << 1 | 1].num) & (mod ^ tr[p].is);
}
node merge(node a, node b)
{
node c;
c.sum = a.sum & b.sum;
c.is = (a.num & b.num) | a.is | b.is;
c.num = (a.num ^ b.num) & (mod ^ c.is);
return c;
}
void build(int p, int l, int r)
{
tr[p].siz = r - l + 1;
tr[p].lazy = mod;
if (l == r)
{
tr[p].num = (mod ^ val[l]);
tr[p].sum = val[l];
return;
}
int mid = l + r >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
push_up(p);
}
void modify(int p, int l, int r, int pos, int nu)
{
if (l == r)
{
tr[p].sum = nu;
tr[p].num = (mod ^ nu);
return;
}
push_down(p);
int mid = l + r >> 1;
if (pos <= mid)
modify(p << 1, l, mid, pos, nu);
else
modify(p << 1 | 1, mid + 1, r, pos, nu);
push_up(p);
}
void modify_and(int p, int l, int r, int ql, int qr, int nu)
{
if (l >= ql && r <= qr)
{
if (tr[p].siz == 1)
{
tr[p].sum &= nu;
tr[p].num |= (mod ^ nu);
}
else
{
tr[p].sum &= nu;
tr[p].lazy &= nu;
tr[p].num &= nu;
tr[p].is |= (mod ^ nu);
}
return;
}
push_down(p);
int mid = l + r >> 1;
if (ql <= mid)
modify_and(p << 1, l, mid, ql, qr, nu);
if (qr > mid)
modify_and(p << 1 | 1, mid + 1, r, ql, qr, nu);
push_up(p);
}
node query_bit(int p, int l, int r, int ql, int qr)
{
if (l >= ql && r <= qr)
{
return tr[p];
}
push_down(p);
int mid = l + r >> 1;
node ans = {0, 0, 0, 0, 0};
if (ql <= mid)
ans = merge(ans, query_bit(p << 1, l, mid, ql, qr));
if (qr > mid)
ans = merge(ans, query_bit(p << 1 | 1, mid + 1, r, ql, qr));
push_up(p);
return ans;
}
int query_pos(int p, int l, int r, int ql, int qr, int nu)
{ // 已经被提取的最高位
if (l == r)
{
return l;
}
push_down(p);
int mid = l + r >> 1;
int ans = 0;
if (l >= ql && r <= qr)
{
if (!(tr[p << 1].is & nu) && !(tr[p << 1].sum & nu))
{
ans = query_pos(p << 1, l, mid, ql, qr, nu);
}
else
{
ans = query_pos(p << 1 | 1, mid + 1, r, ql, qr, nu);
}
}
else
{
if (ql <= mid)
ans |= query_pos(p << 1, l, mid, ql, qr, nu);
if (qr > mid)
ans |= query_pos(p << 1 | 1, mid + 1, r, ql, qr, nu);
}
push_up(p);
return ans;
}
int query_val(int p, int l, int r, int ql, int qr)
{
if (l >= ql && r <= qr)
{
return tr[p].sum;
}
push_down(p);
int mid = l + r >> 1;
int ans = mod;
if (ql <= mid)
ans &= query_val(p << 1, l, mid, ql, qr);
if (qr > mid)
ans &= query_val(p << 1 | 1, mid + 1, r, ql, qr);
push_up(p);
return ans;
}
void solve()
{
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> val[i];
build(1, 1, n);
while (q--)
{
int op;
cin >> op;
if (op == 1)
{
int l, r, x;
cin >> l >> r >> x;
modify_and(1, 1, n, l, r, x);
}
else if (op == 2)
{
int s, x;
cin >> s >> x;
modify(1, 1, n, s, x);
}
else
{
int l, r;
cin >> l >> r;
if (l == r)
{
cout << 0 << endl;
continue;
}
node nu = query_bit(1, 1, n, l, r);
// cout << nu.sum << endl;
// cout << nu.num << endl;
// cout << nu.is << endl;
int res = ((nu.is | nu.sum) ^ mod) & mod;
// cout << res << endl;
int ws = -1;
for (int i = 62; i >= 0; i--)
{
if (res & (1ll << i))
{
ws = i;
break;
}
}
int pos = query_pos(1, 1, n, l, r, (1ll << ws));
// cout << pos << endl;
int ans = mod;
if (pos != l)
{
ans &= query_val(1, 1, n, l, pos - 1);
}
if (pos != r)
{
ans &= query_val(1, 1, n, pos + 1, r);
}
cout << ans << endl;
}
}
// cout << -1 << endl;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
// cout << -1 << endl;
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
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
Wrong Answer
time: 1ms
memory: 5708kb
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...
output:
1153048052409963530 35184372088832 176025477579040 580969956778186760
result:
wrong answer 1st lines differ - expected: '1568091718842717482', found: '1153048052409963530'