QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#834661 | #9727. Barkley III | remain11 | WA | 0ms | 3844kb | C++20 | 6.6kb | 2024-12-27 21:22:35 | 2024-12-27 21:22:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using ull = unsigned long long;
constexpr int N = 3e5 + 5;
const ll inf = 1e16;
template<class T>
T& cmax(T &a, const T &b) {if (a < b) a = b; return a;}
template<class T>
T& cmin(T &a, const T &b) {if (a > b) a = b; return a;}
//区间修改
template<class T, class S>
struct Segment {
int n;
vector<T> tree;
vector<S> lazy;
Segment() {}
Segment(int n) {init(n);}
Segment(vector<T> &a) : n(a.size() - 1), tree((n + 1) << 2), lazy((n + 1) << 2) {
build(1, 1, n, a);
}
void init(int n) {
this->n = n;
tree.resize((n + 1) << 2);
lazy.resize((n + 1) << 2);
}
void pushup(int now){
tree[now] = tree[now << 1] + tree[now << 1 | 1];
}
void build(int now, int left, int right, vector<T> &a){ //[l , r]
if(left == right){
tree[now] = T(a[left]);
return ;
}
int mid = (left + right) >> 1;
build(now << 1, left, mid, a);
build(now << 1 | 1, mid + 1, right, a);
pushup(now);
}
void push(int now, const S &x){
lazy[now].push(x);
tree[now].push(x);
}
void pushdown(int now){
push(now << 1, lazy[now]);
push(now << 1 | 1, lazy[now]);
lazy[now] = S();
}
void modify(int now, int l, int r, int al, int ar, const S &x) { //[l , r]
if(al > r || ar < l){
return;
}
if(al <= l && ar >= r){
push(now, x);
return;
}
pushdown(now);
int mid = (l + r) >> 1 ;
modify(now << 1, l, mid, al, ar, x);
modify(now << 1 | 1, mid + 1, r, al, ar, x);
pushup(now);
}
void modify(int al, int ar, const S &x){
modify(1, 1, n, al, ar, x);
}
void modify(int now, int l, int r, int pos, const T &x) { //[l , r]
if (l == r) {
tree[now] = x;
return;
}
pushdown(now);
int mid = (l + r) >> 1 ;
if (pos <= mid) modify(now << 1, l, mid, pos, x);
else modify(now << 1 | 1, mid + 1, r, pos, x);
pushup(now);
}
void modify(int pos, const T &x){
modify(1, 1, n, pos, x);
}
T ask(int now, int l, int r, int al, int ar) {
if(al > r || ar < l){
return T();
}
if(al <= l && ar >= r){
return tree[now];
}
pushdown(now);
int mid = (l + r) >> 1 ;
return ask(now << 1, l, mid, al, ar) + ask(now << 1 | 1, mid + 1, r, al, ar);
}
T ask(int al, int ar) {
return ask(1, 1, n, al, ar);
}
template<class F>
int ask_first(int now, int l, int r, const F &f) {
if (l == r) {
return l;
}
pushdown(now);
int mid = (l + r) >> 1 ;
if (f(tree[now << 1])) {
return ask_first(now << 1, l, mid, f);
} else {
return ask_first(now << 1 | 1, mid + 1, r, f);
}
}
template<class F>
int ask_first(const F &f) {
if (!f(tree[1])) return 0;
return ask_first(1, 1, n, f);
}
template<class F>
int ask_last(int now, int l, int r, const F &f) {
if (l == r) {
return l;
}
pushdown(now);
int mid = (l + r) >> 1 ;
if (f(tree[now << 1 | 1])) {
return ask_last(now << 1 | 1, mid + 1, r, f);
} else {
return ask_last(now << 1, l, mid, f);
}
}
template<class F>
int ask_last(const F &f) {
if (!f(tree[1])) return 0;
return ask_last(1, 1, n, f);
}
template<class F>
int ask_one(int now, int l, int r, int al, int ar, const F &f) {
if (l == r) return l;
pushdown(now);
int mid = (l + r) >> 1 ;
if (al <= l && r <= ar) {
// cout << l << " " << r << " " << al << " " << ar << "\n";
if (f(tree[now << 1])) return ask_one(now << 1, l, mid, al, ar, f);
if (f(tree[now << 1 | 1])) return ask_one(now << 1 | 1, mid + 1, r, al, ar, f);
return 0;
}
int res = 0;
if (al <= mid) res = ask_one(now << 1, l, mid, al, ar, f);
if (res != 0) return res;
return ask_one(now << 1 | 1, mid + 1, r, al, ar, f);
}
template<class F>
int ask_one(int al, int ar, const F &f) {
// if (!f(tree[1])) return 0;
return ask_one(1, 1, n, al, ar, f);
}
};
struct Info1 {
ll x;
Info1() : x(LONG_LONG_MAX) {}
Info1(ll x) : x(x) {}
void push(const Info1 &a) {
x &= a.x;
}
friend Info1 operator + (const Info1 &a, const Info1 &b) {
return a.x & b.x;
}
};
struct Info2 {
ll x, y, sz;
Info2() : x(0), y(0), sz(1) {}
Info2(ll x, ll y, ll sz) : x(x), y(y), sz(sz) {}
void push(const Info1 &a) {
if (sz == 1) {
x |= LONG_LONG_MAX ^ a.x;
} else {
y |= (LONG_LONG_MAX ^ a.x);
x &= a.x;
}
}
friend Info2 operator + (const Info2 &a, const Info2 &b) {
ll x = a.x ^ b.x;
ll y = (a.y | b.y) | (a.x & b.x);
x = x ^ (x & y);
// cout << "l : " << bitset<4>(a.x) << " " << bitset<4>(a.y) << "\n";
// cout << "r : " << bitset<4>(b.x) << " " << bitset<4>(b.y) << "\n";
// cout << bitset<4>(x) << " " << bitset<4>(y) << "\n";
return {x, y, a.sz + b.sz};
}
};
void solve() {
int n, q;
cin >> n >> q;
vector<ll> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
Segment<Info1, Info1> t1(n);
Segment<Info2, Info1> t2(n);
for (int i = 1; i <= n; ++i) {
t1.modify(i, a[i]);
Info2 tmp;
tmp.push(a[i]);
t2.modify(i, tmp);
}
while(q--) {
int op, l, r;
ll x;
cin >> op >> l;
if (op == 1) {
cin >> r >> x;
t1.modify(l, r, x);
t2.modify(l, r, x);
} else if (op == 2) {
cin >> x;
t1.modify(l, x);
Info2 tmp;
tmp.push(x);
// cout << x << " " << bitset<4>(tmp.x) << "\n";
t2.modify(l, tmp);
} else {
cin >> r;
auto [ox, oy, sz] = t2.ask(l, r);
if (ox == 0) {
cout << t1.ask(l, r).x << "\n";
continue;
}
int pos = __lg(ox);
int id = t1.ask_one(l, r, [&](const Info1 &info) {
return !(info.x >> pos & 1);
});
// cout << t1.ask(id, id).x << "\n";
// ll la = t1.ask(l, id - 1).x, ra = t1.ask(id + 1, r).x;
// cout << id << " " << pos << " " << la << " " << ra << "\n";
cout << (t1.ask(l, id - 1).x & t1.ask(id + 1, r).x) << "\n";
}
}
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t = 1;
// cin >> t;
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
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: 0
Accepted
time: 0ms
memory: 3764kb
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:
1568091718842717482 35184908959744 176025477579040 8795942500783873690
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3844kb
input:
100 100 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...
output:
576531121047601152 0 0 3612454262104133153 153122391625564161 4263579105072360993 70368744177664 633397148123136 0 12952010752 1152922054496880128 1730020640668059136 3458764518266578433 67108864 576531718266945536 0 77309673472 1729382296723653632 0 1730020640668059136 3533641810948498945 0 0 17300...
result:
wrong answer 2nd lines differ - expected: '1', found: '0'