QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865522 | #9727. Barkley III | starryskymeow | WA | 0ms | 3712kb | C++20 | 5.8kb | 2025-01-21 19:28:06 | 2025-01-21 19:28:17 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...) 114514
#endif
using namespace std;
using LL = long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
const int INF = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int N = 3e5 + 10;
template <class info, class tag>
class LSGT {
std::vector<info> node;
std::vector<tag> ta;
int siz;
void build(int idx, int l, int r) {
if (l == r)
return;
int mid = (l + r) >> 1;
build(idx << 1, l, mid), build(idx << 1 | 1, mid + 1, r);
node[idx] = node[idx << 1] + node[idx << 1 | 1];
}
template <typename T>
void build(int idx, int l, int r, const std::vector<T> &vec) {
if (l == r) {
node[idx] = vec[l];
return;
}
int mid = (l + r) >> 1;
build(idx << 1, l, mid, vec), build(idx << 1 | 1, mid + 1, r, vec);
node[idx] = node[idx << 1] + node[idx << 1 | 1];
}
void pushdown(int idx) {
if (ta[idx].empty())
return;
ta[idx << 1].apply(ta[idx]);
ta[idx << 1 | 1].apply(ta[idx]);
node[idx << 1].apply(ta[idx]);
node[idx << 1 | 1].apply(ta[idx]);
ta[idx] = {};
}
void modify(int idx, int l, int r, int ql, int qr, const tag &add) {
if (ql <= l && qr >= r) {
ta[idx].apply(add);
node[idx].apply(add);
return;
}
pushdown(idx);
int mid = (l + r) >> 1;
if (ql <= mid)
modify(idx << 1, l, mid, ql, qr, add);
if (qr > mid)
modify(idx << 1 | 1, mid + 1, r, ql, qr, add);
node[idx] = node[idx << 1] + node[idx << 1 | 1];
}
void modify(int idx, int l, int r, int d, LL x) {
if (l == r) {
node[idx] = x;
return;
}
pushdown(idx);
int mid = (l + r) >> 1;
if (d <= mid)
modify(idx << 1, l, mid, d, x);
if (d > mid)
modify(idx << 1 | 1, mid + 1, r, d, x);
node[idx] = node[idx << 1] + node[idx << 1 | 1];
}
info query(int idx, int l, int r, int ql, int qr) {
if (ql <= l && qr >= r)
return node[idx];
pushdown(idx);
int mid = (l + r) >> 1;
if (qr <= mid)
return query(idx << 1, l, mid, ql, qr);
else if (ql > mid)
return query(idx << 1 | 1, mid + 1, r, ql, qr);
else
return query(idx << 1, l, mid, ql, qr) + query(idx << 1 | 1, mid + 1, r, ql, qr);
}
LL query(int idx, int l, int r, int ql, int qr, LL quer) {
if (l == r) {
return node[idx].sum;
}
pushdown(idx);
int mid = (l + r) >> 1;
LL resl = (~node[idx << 1].sum & quer) && ql <= mid ? query(idx << 1, l, mid, ql, qr, quer) : -1;
if (resl != -1)
return resl;
return (~node[idx << 1 | 1].sum & quer) && qr > mid ? query(idx << 1 | 1, mid, r, ql, qr, quer) : -1;
}
public:
LSGT(const int size) : node(size << 2), ta(size << 2), siz(size) {
build(1, 1, siz);
}
template <typename T>
LSGT(const std::vector<T> &vec) : node(vec.size() << 2), ta(vec.size() << 2), siz(vec.size() - 1) {
build(1, 1, siz, vec);
}
void modify(int ql, int qr, const tag &add) {
modify(1, 1, siz, ql, qr, add);
}
void modify(int d, LL x) {
modify(1, 1, siz, d, x);
}
info query(int ql, int qr) {
return query(1, 1, siz, ql, qr);
}
LL query(int ql, int qr, LL quer) {
return query(1, 1, siz, ql, qr, quer);
}
};
struct tag {
LL mask;
tag(LL mask) : mask(mask) {}
tag() : mask(-1) {}
bool empty() const {
return mask == -1;
}
void apply(tag t) {
mask &= t.mask;
}
};
struct info {
LL tg, sum;
info() {}
info(LL sum) : tg(-1), sum(sum) {}
info(LL tg, LL sum) : tg(tg), sum(sum) {}
friend info operator+(info a, info b) {
return info{(a.sum | b.sum) & a.tg & b.tg, a.sum & b.sum};
}
void apply(const tag &o) {
if (tg != -1)
tg &= o.mask;
sum &= o.mask;
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<LL> arr(n + 1);
for (int i = 1; i <= n; i++) cin >> arr[i];
LSGT<info, tag> tr(arr);
while (q--) {
int op;
cin >> op;
if (op == 1) {
LL l, r, mask;
cin >> l >> r >> mask;
tr.modify(l, r, mask);
} else if (op == 2) {
LL s, x;
cin >> s >> x;
tr.modify(s, x);
} else {
int l, r;
cin >> l >> r;
info res = tr.query(l, r);
int quer = -1;
for (int i = 62; i >= 0; i--) {
if (((res.tg >> i) & 1) && !((res.sum >> i) & 1)) {
quer = 1LL << i;
break;
}
}
LL badpig = -1;
if (quer != -1) {
badpig = tr.query(l, r, quer);
}
cout << (res.sum | (res.tg & ~badpig)) << '\n';
}
}
}
signed main() {
#ifdef LOCAL
clock_t tttttttt = clock();
freopen("in.txt", "r", stdin);
#endif
#ifndef LOCAL
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
//*****************************************************************
int t = 1;
// cin >> t;
while (t--) solve();
//*****************************************************************
#ifdef LOCAL
cerr << "Time Used: " << fixed << setprecision(3) << (clock() - tttttttt) / (CLOCKS_PER_SEC / 1000.0) << " ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 0ms
memory: 3712kb
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 35184908959744 35287989223424 580969956778186760
result:
wrong answer 1st lines differ - expected: '1568091718842717482', found: '1153048052409963530'